xQuery子串问题
我现在有一个文件的完整路径作为字符串,例如:
"/db/Liebherr/Content_Repository/Techpubs/Topics/HyraulicPowerDistribution/Released/TRN_282C_HYD_MOD_1_Drive_Shaft_Rev000.xml"
但是,现在我只需要取出文件夹路径,因此它将是上面的字符串,没有最后一个反斜杠内容,例如:
"/db/Liebherr/Content_Repository/Techpubs/Topics/HyraulicPowerDistribution/Released/"
但似乎 substring() xQuery 中的函数只有 substring(string,start,len) 或 substring(string,start),我试图找出一种方法来指定反斜杠的最后一次出现,但没有运气。
专家可以帮忙吗?谢谢!
I now have a full path for a file as a string like:
"/db/Liebherr/Content_Repository/Techpubs/Topics/HyraulicPowerDistribution/Released/TRN_282C_HYD_MOD_1_Drive_Shaft_Rev000.xml"
However, now I need to take out only the folder path, so it will be the above string without the last back slash content like:
"/db/Liebherr/Content_Repository/Techpubs/Topics/HyraulicPowerDistribution/Released/"
But it seems that the substring() function in xQuery only has substring(string,start,len) or substring(string,start), I am trying to figure out a way to specify the last occurence of the backslash, but no luck.
Could experts help? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试使用 tokenize() 函数(用于将字符串拆分为其组成部分),然后使用除最后一部分之外的所有内容重新组装它。
有关这些函数的更多详细信息,请查看它们的参考页面:
Try out the tokenize() function (for splitting a string into its component parts) and then re-assembling it, using everything but the last part.
For more details on these functions, check out their reference pages:
fn:replace 可以使用正则表达式完成这项工作:
fn:replace can do the job with a regular expression:
即使使用单个 XPath 2.0(XQuery 的子集)表达式也可以完成此操作:
其中
$fullPath
应替换为实际字符串,例如 >:This can be done even with a single XPath 2.0 (subset of XQuery) expression:
where
$fullPath
should be substituted with the actual string, such as:以下代码进行标记,删除最后一个标记,将其替换为空字符串,然后连接回来。
它似乎在 try.zorba-xquery.com 上返回了所需的结果。这有帮助吗?
The following code tokenizes, removes the last token, replaces it with an empty string, and joins back.
It seems to return the desired result on try.zorba-xquery.com. Does this help?