<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>发布于 2011-08-16 21:11:33
I. XPath 2.0
使用此XPath 2.0表达式
max(/*/*/*/*/*/*/nor:ProductID) min(/*/*/*/*/*/*/nor:ProductID)使用此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的验证。
XSLTI.XSLT1.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<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引擎的来注册名称空间和前缀到它的绑定。
发布于 2011-08-16 18:28:11
使用此XPath查找具有最大nor:ProductID的nor:tuple
//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要查找最小值,请用<替换>。
https://stackoverflow.com/questions/7076041
复制相似问题