Xml 嵌套的 Xpath 表达式 XML
Xml Xpath Expression for Nested XML
我有一个XML
<font-text content-format="howdy" data-type="text">
<Index>1</Index>
<Root>1</Root>
<Result>302</Result>
</font-text>
如果我想取出格式为“302-01-01”的 "Index"、"Root" 和 "Result" 值,上述 XMS 的 Xpath 表达式是什么? =13=]
XPath string-join()
和 format-number()
函数来拯救。
format-number()
XSLT 2.0 中存在函数
已从 XSLT 3.0 移至 XPath 3.0
XPath 3.0
string-join((/font-text/Result/text(), format-number(/font-text/Root/text(),'00'), format-number(/font-text/Index/text(),'00')), "-")
XPath 2.0
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
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)
)
我有一个XML
<font-text content-format="howdy" data-type="text">
<Index>1</Index>
<Root>1</Root>
<Result>302</Result>
</font-text>
如果我想取出格式为“302-01-01”的 "Index"、"Root" 和 "Result" 值,上述 XMS 的 Xpath 表达式是什么? =13=]
XPath string-join()
和 format-number()
函数来拯救。
format-number()
XSLT 2.0 中存在函数
已从 XSLT 3.0 移至 XPath 3.0
XPath 3.0
string-join((/font-text/Result/text(), format-number(/font-text/Root/text(),'00'), format-number(/font-text/Index/text(),'00')), "-")
XPath 2.0
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
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)
)