<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的驗證。 –