<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:nor="http://schemas.cordys.com/NorthwindMetadata">
<soapenv:Header/>
<soapenv:Body>
<nor:UpdateOrder_x0020_Details reply="yes" commandUpdate="no" preserveSpace="no" batchUpdate="no">
<nor:tuple>
<nor:new>
<nor:Order_x0020_Details qAccess="0" qConstraint="0" qInit="0" qValues="">
<nor:OrderID>11113</nor:OrderID>
<nor:ProductID>43</nor:ProductID>
<nor:UnitPrice>36.0000</nor:UnitPrice>
<nor:Quantity>25</nor:Quantity>
<nor:Discount>0</nor:Discount>
</nor:Order_x0020_Details>
</nor:new>
</nor:tuple>
<nor:tuple>
<nor:new>
<nor:Order_x0020_Details qAccess="0" qConstraint="0" qInit="0" qValues="">
<nor:OrderID>11113</nor:OrderID>
<nor:ProductID>30</nor:ProductID>
<nor:UnitPrice>99.000</nor:UnitPrice>
<nor:Quantity>10</nor:Quantity>
<nor:Discount>0</nor:Discount>
</nor:Order_x0020_Details>
</nor:new>
</nor:tuple>
<nor:tuple>
<nor:new>
<nor:Order_x0020_Details qAccess="0" qConstraint="0" qInit="0" qValues="">
<nor:OrderID>11113</nor:OrderID>
<nor:ProductID>40</nor:ProductID>
<nor:UnitPrice>88.0000</nor:UnitPrice>
<nor:Quantity>19</nor:Quantity>
<nor:Discount>0</nor:Discount>
</nor:Order_x0020_Details>
</nor:new>
</nor:tuple>
</nor:UpdateOrder_x0020_Details>
</soapenv:Body>
</soapenv:Envelope>
3
A
回答
0
使用这个XPath从下面的数据找出产品ID的最小值和最大值找到nor:tuple
,最大nor:ProductID
:
//nor:tuple[
not(following-sibling::nor:tuple/nor:new//nor:ProductID > nor:new//nor:ProductID
or
preceding-sibling::nor:tuple/nor:new//nor:ProductID > nor:new//nor:ProductID)
]
要找到最大值(在你的例如43
):
//nor:tuple[
not(following-sibling::nor:tuple/nor:new//nor:ProductID > nor:new//nor:ProductID
or
preceding-sibling::nor:tuple/nor:new//nor:ProductID > nor:new//nor:ProductID)
]/nor:new//nor:ProductID
为了找到最小值,与<
替换>
。
1
I.的XPath 2.0
使用这个XPath 2.0表达式:分别
max(/*/*/*/*/*/*/nor:ProductID)
和,:
min(/*/*/*/*/*/*/nor:ProductID)
II。的XPath 1.0
使用这个XPath 1.0表达式:
/*/*/*/*/*/*/nor:ProductID
[not(. > following::nor:ProductID)
and
not(. > preceding::nor:ProductID)
]
和,分别为:
/*/*/*/*/*/*/nor:ProductID
[not(. < following::nor:ProductID)
and
not(. < preceding::nor:ProductID)
]
这里是两种溶液的基于XSLT的验证:
I. XSLT 1.0:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:nor="http://schemas.cordys.com/NorthwindMetadata">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
min: <xsl:value-of select=
"/*/*/*/*/*/*/nor:ProductID
[not(. > following::nor:ProductID)
and
not(. > preceding::nor:ProductID)
]
"/>
<xsl:text>/ max: </xsl:text>
<xsl:value-of select=
"/*/*/*/*/*/*/nor:ProductID
[not(. < following::nor:ProductID)
and
not(. < preceding::nor:ProductID)
]
"/>
</xsl:template>
</xsl:stylesheet>
当该变换被应用所提供的XML文档:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:nor="http://schemas.cordys.com/NorthwindMetadata">
<soapenv:Header/>
<soapenv:Body>
<nor:UpdateOrder_x0020_Details reply="yes" commandUpdate="no" preserveSpace="no" batchUpdate="no">
<nor:tuple>
<nor:new>
<nor:Order_x0020_Details qAccess="0" qConstraint="0" qInit="0" qValues="">
<nor:OrderID>11113</nor:OrderID>
<nor:ProductID>43</nor:ProductID>
<nor:UnitPrice>36.0000</nor:UnitPrice>
<nor:Quantity>25</nor:Quantity>
<nor:Discount>0</nor:Discount>
</nor:Order_x0020_Details>
</nor:new>
</nor:tuple>
<nor:tuple>
<nor:new>
<nor:Order_x0020_Details qAccess="0" qConstraint="0" qInit="0" qValues="">
<nor:OrderID>11113</nor:OrderID>
<nor:ProductID>30</nor:ProductID>
<nor:UnitPrice>99.000</nor:UnitPrice>
<nor:Quantity>10</nor:Quantity>
<nor:Discount>0</nor:Discount>
</nor:Order_x0020_Details>
</nor:new>
</nor:tuple>
<nor:tuple>
<nor:new>
<nor:Order_x0020_Details qAccess="0" qConstraint="0" qInit="0" qValues="">
<nor:OrderID>11113</nor:OrderID>
<nor:ProductID>40</nor:ProductID>
<nor:UnitPrice>88.0000</nor:UnitPrice>
<nor:Quantity>19</nor:Quantity>
<nor:Discount>0</nor:Discount>
</nor:Order_x0020_Details>
</nor:new>
</nor:tuple>
</nor:UpdateOrder_x0020_Details>
</soapenv:Body>
</soapenv:Envelope>
有用,正确的结果产生:
min: 30/ max: 43
II。 XSLT 2.0:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:nor="http://schemas.cordys.com/NorthwindMetadata">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
max: <xsl:sequence select=
"max(/*/*/*/*/*/*/nor:ProductID)"/>
<xsl:text>/ min: </xsl:text>
<xsl:sequence select=
"min(/*/*/*/*/*/*/nor:ProductID)"/>
</xsl:template>
</xsl:stylesheet>
当这种转变是在同一个XML文档(以上)应用,再次想要的,正确的答案是生产:
max: 43/ min: 30
最后一点:一如往常当在XPath表达式中添加了前缀名称时,必须使用已使用的XPath引擎的API来注册名称空间以及该前缀的绑定。
相关问题
- 1. 我怎样才能提取使用grep和正则表达式
- 2. 我怎样才能用正则表达式来标记这个?
- 3. 我怎样才能使PHP
- 4. 正则表达式 - 我怎样才能做到这一点?
- 5. 我怎样才能在正则表达式
- 6. 我怎样才能通过正则表达式捕获这个?
- 7. 我怎样才能抓住字符|与正则表达式?
- 8. 我怎样才能获得密码正则表达式?
- 9. 我怎样才能做到这个正则表达式?
- 10. 我怎样才能获得属性表达式为属性
- 11. 我怎样才能识别正则表达式
- 12. 我怎样才能grep有两个表达式的文件?
- 13. 我怎样才能
- 14. 我怎样才能
- 15. 我怎样才能
- 16. 我怎样才能
- 17. 我怎样才能达到radiobuttonlist?
- 18. 我怎样才能达到风效?
- 19. 我怎样才能用ajax
- 20. 我怎样才能用jQuery
- 21. 我怎样才能让一个多属性的lambda表达式使用LINQ
- 22. 正则表达式 - 我怎样才能排除表达与复制的字符
- 23. 我使用XPath表达式
- 24. 我怎样才能使用神功
- 25. 我怎样才能使用xp_fileexist
- 26. 我怎样才能使用CompiledQuery
- 27. pdf.js:我们怎样才能使用pdf.js
- 28. 我怎样才能在不使用硒
- 29. 我怎样才能使用TRIGGER
- 30. 我怎样才能使用WMI
好问题,+1。查看我对两种不同(XPath 1.0和XPath 2.0)单行表达式的答案。还提供了完整的基于XSLT的验证。 –