嵌套 XML 的 Xml Xpath 表达式

Xml Xpath Expression for Nested XML

我有一个 XML

1
2
3
4
5
<font-text content-format="howdy" data-type="text">
<Index>1</Index>
<Root>1</Root>
<Result>302</Result>
</font-text>

如果我想取出 "Index","Root",上述 XMS 的 Xpath 表达式是什么


XPath string-join() 和 format-number() 函数来救援。

format-number() 函数存在于 XSLT 2.0

它已从 XSLT 3.0 移至 XPath 3.0

XPath 3.0

1
string-join((/font-text/Result/text(), format-number(/font-text/Root/text(),'00'), format-number(/font-text/Index/text(),'00')),"-")

XPath 2.0

1
2
3
4
string-join((/font-text/Result/text()
, substring(concat("00", /font-text/Root/text()), string-length(concat("00",/font-text/Root/text())) - 1)
, substring(concat("00", /font-text/Index/text()), string-length(concat("00",/font-text/Index/text())) - 1))
,"-")

XPath 1.0

1
2
3
4
5
6
concat(/font-text/Result/text()
,"-"
, substring(concat("00", /font-text/Root/text()), string-length(concat("00",/font-text/Root/text())) - 1)
,"-"
, substring(concat("00", /font-text/Index/text()), string-length(concat("00",/font-text/Index/text())) - 1)
)

相关讨论

  • 使用"w3.org/XML/1998/namespace"编译...它的说法是找不到函数:string-join
  • 在这里查看:w3.org/TR/xquery-operators/#func-string-join
  • 使用 Java xml"xPath.compile(expression).evaluate(node);"。在这里不工作
  • 我通过使用不同版本的 XPath 展示了三种不同的解决方案。你都试过了吗?
  • 我的不好,它起作用了...感谢您的帮助,非常感谢

以上是嵌套 XML 的 Xml Xpath 表达式的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>