gpt4 book ai didi

c# - XPath 后子串

转载 作者:行者123 更新时间:2023-11-30 22:31:23 24 4
gpt4 key购买 nike

给定以下 XML:

<?xml version="1.0"?>
<purchaseOrder orderDate="1999-10-20">
<shipTo country="US">
<name>Alice Smith</name>
<street>123 Maple Street</street>
<city>Mill Valley</city>
<state>CA</state>
<zip>90952</zip>
</shipTo>
<billTo country="US">
<name>Robert Smith</name>
<street>8 Oak Avenue</street>
<city>Old Town</city>
<state>PA</state>
<zip>95819</zip>
</billTo>
<comment>Hurry, my lawn is going wild!</comment>
<items>
<item partNum="872-AA">
<productName>Lawnmower</productName>
<quantity>1</quantity>
<USPrice>148.95</USPrice>
<comment>Confirm this is electric</comment>
</item>
<item partNum="926-AA">
<productName>Baby Monitor</productName>
<quantity>1</quantity>
<USPrice>39.98</USPrice>
<shipDate>1999-05-21</shipDate>
</item>
</items>
</purchaseOrder>

如何从第 2 项的 USPrice 中选择“98”。我试过:

purchaseOrder/items/item[USPrice[text()='39.98']]/USPrice/substring-after(.,'.')

但它一直给我错误 'has an invalid token'

如果我尝试:

purchaseOrder/items/item[USPrice[text()='39.98']]/USPrice/text()[substring-after(.,'.')]

purchaseOrder/items/item[USPrice[text()='39.98']]/USPrice[substring-after(text(),'.')]

我得到的 '39.98' 也是错误的。

我正在使用此处的网站进行测试:

http://www.xmlme.com/XpathTool.aspx

最佳答案

严格来说,您不能使用 xpath 1.0 执行此操作

使用以下 XSLT 会起作用,但我认为这不是您所需要的

<xsl:value-of select="substring-after(purchaseOrder/items/item[2]/USPrice,'.')"/>

更多信息请引用这个类似的问题

How to apply the XPath function 'substring-after'

关于c# - XPath 后子串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9274115/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com