我想要合并两个xpath
个函数
a - 返回子域名字符串,如果它不是“www”
replace(substring-before(replace(//url,"(https?://)",""),"."),"www","")
b - 返回子文件夹名称
substring-before(replace(//url,"(https?://[^/]+/)",""),"/")
如果a为空,是否有可能返回b的xpath,否则返回?
示例:
http://aaaa.something.com/bbbb should return "aaaa"
http://www.something.com/bbbb should return "bbbb"
答案 0 :(得分:1)
如果a为空,是否有可能返回b的xpath, 否则它返回一个?
通常的XPath 2.0习惯用法是
(a, b)[1]
(此处的效率取决于管道评估,但我认为您可以假设在给定X[1]
时任何一个不太合适的处理器将避免在X之外评估第一个项目。)
答案 1 :(得分:0)
在深入了解@ Michael的建议之后,我找到了答案:
(a, b)[string-length() > 0][1]
在我的例子中翻译成:
(replace(substring-before(replace(//url,"(https?://)",""),"."),"www",""), replace(replace(//url,"(https?://[^/]+[/])",""),"[/+].*",""))[string-length() > 0][1]