2011-08-16 5 views
3
<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> 
+0

좋은 질문입니다. +1. 두 가지 다른 (XPath 1.0 및 XPath 2.0) one-liner 표현에 대한 내 대답을보십시오. 완벽한 XSLT 기반 검증도 제공됩니다. –

답변

0

사용이 XPath를 사용하여 아래 데이터에서 제품 ID의 최소 및 최대 값을 찾을 수 있습니다에

//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 :

<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> 

원하는 정확한 결과 제작된다 :이 변환은 제공된 XML 문서에인가

<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(. &lt; following::nor:ProductID) 
        and 
        not(. &lt; preceding::nor:ProductID) 
        ] 
    "/> 
</xsl:template> 
</xsl:stylesheet> 

min: 30/ max: 43 

II. XSLT 2.0 :

이 변환 (위) 같은 XML 문서에 적용되는
<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> 

, 다시 원하는, 정답은 생산 :

max: 43/ min: 30 

최종 참고 : 언제나처럼 XPath 표현식에 접두어가 붙은 이름이있을 때, 사용 된 XPath 엔진의 API가 네임 스페이스 및 접두사의 바인딩을 등록하는 데 사용되어 있어야합니다.

관련 문제