2013-10-04 58 views
0

我正在嘗試獲取LandLine_ExtId基準的最大值和最小值不屬於該屬性操作。 返回錯誤獲取節點不能正常工作的最大值

XML輸入Landline_ExtId用行動值=德爾最大值

<Landline_ExtId action='add'>771534777880</Landline_ExtId> 
<Landline_ExtId action='add'>771534777881</Landline_ExtId> 
<Landline_ExtId action='add'>771534777882</Landline_ExtId> 
<Landline_ExtId action='add'>771534777883</Landline_ExtId> 
<Landline_ExtId action='add'>771534777884</Landline_ExtId> 
<Landline_ExtId action='add'>771534777885</Landline_ExtId> 
<Landline_ExtId action='add'>771534777886</Landline_ExtId> 
<Landline_ExtId action='add'>771534777887</Landline_ExtId> 
<Landline_ExtId action='add'>771534777888</Landline_ExtId> 
<Landline_ExtId action='add'>771534777889</Landline_ExtId> 
<Landline_ExtId action='del'>551534882800</Landline_ExtId> 
<Landline_ExtId action='del'>551534882801</Landline_ExtId> 
<Landline_ExtId action='del'>551534882802</Landline_ExtId> 
<Landline_ExtId action='del'>551534882803</Landline_ExtId> 
<Landline_ExtId action='del'>551534882804</Landline_ExtId> 
<Landline_ExtId action='del'>551534882805</Landline_ExtId> 
<Landline_ExtId action='del'>551534882806</Landline_ExtId> 
<Landline_ExtId action='del'>551534882807</Landline_ExtId> 
<Landline_ExtId action='del'>551534882808</Landline_ExtId> 
<Landline_ExtId action='del'>551534882809</Landline_ExtId> 

XSLT:

  <?xml version="1.0" encoding="UTF-8"?> 
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
     <xsl:template match="/"> 
    <xsl:element name="getMaxOld"> 
    <xsl:value-of select="/Data/Landline_ExtId[not(. &lt;  /Data/Landline_ExtId[@action='del'])][1]"/> 
     </xsl:element> 
    <xsl:element name="getMinOld"> 
    <xsl:value-of select="/Data/Landline_ExtId[not(. &gt; /Data/Landline_ExtId[@action='del'])][1]"/> 
     </xsl:element> 
      <xsl:element name="getMaxNew"> 
     <xsl:value-of select="/Data/Landline_ExtId[not(. &lt; /Data/Landline_ExtId[@action='add'])][1]"/> 
     </xsl:element> 
     <xsl:element name="getMinNew"> 
    <xsl:value-of select="/Data/Landline_ExtId[not(. &gt; /Da ta/Landline_ExtId[@action='add'])][1]"/> 
    </xsl:element> 
</xsl:template> 


    </xsl:stylesheet> 

我得到錯誤的值GetMaxOld。取而代之的551534882809,771534777880被返回

回答

1

你缺少謂語[@action='del']找到您的最小值和最大值,見下:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

    <xsl:template match="/"> 
     <data> 
      <getMaxOld> 
       <xsl:value-of select="/Data/Landline_ExtId[@action='del'][not(. &lt; /Data/Landline_ExtId[@action='del'])][1]"/> 
      </getMaxOld> 
      <getMinOld> 
       <xsl:value-of select="/Data/Landline_ExtId[@action='del'][not(. &gt; /Data/Landline_ExtId[@action='del'])][1]"/> 
      </getMinOld> 
      <getMaxNew> 
       <xsl:value-of select="/Data/Landline_ExtId[@action='add'][not(. &lt; /Data/Landline_ExtId[@action='add'])][1]"/> 
      </getMaxNew> 
      <getMinNew> 
       <xsl:value-of select="/Data/Landline_ExtId[@action='add'][not(. &gt; /Data/Landline_ExtId[@action='add'])][1]"/> 
      </getMinNew> 
     </data> 
    </xsl:template> 
</xsl:stylesheet> 

當此XML應用:

<?xml version="1.0" encoding="UTF-8"?> 
<Data> 
    <Landline_ExtId action='add'>771534777880</Landline_ExtId> 
    <Landline_ExtId action='add'>771534777881</Landline_ExtId> 
    <Landline_ExtId action='add'>771534777882</Landline_ExtId> 
    <Landline_ExtId action='add'>771534777883</Landline_ExtId> 
    <Landline_ExtId action='add'>771534777884</Landline_ExtId> 
    <Landline_ExtId action='add'>771534777885</Landline_ExtId> 
    <Landline_ExtId action='add'>771534777886</Landline_ExtId> 
    <Landline_ExtId action='add'>771534777887</Landline_ExtId> 
    <Landline_ExtId action='add'>771534777888</Landline_ExtId> 
    <Landline_ExtId action='add'>771534777889</Landline_ExtId> 
    <Landline_ExtId action='del'>551534882800</Landline_ExtId> 
    <Landline_ExtId action='del'>551534882801</Landline_ExtId> 
    <Landline_ExtId action='del'>551534882802</Landline_ExtId> 
    <Landline_ExtId action='del'>551534882803</Landline_ExtId> 
    <Landline_ExtId action='del'>551534882804</Landline_ExtId> 
    <Landline_ExtId action='del'>551534882805</Landline_ExtId> 
    <Landline_ExtId action='del'>551534882806</Landline_ExtId> 
    <Landline_ExtId action='del'>551534882807</Landline_ExtId> 
    <Landline_ExtId action='del'>551534882808</Landline_ExtId> 
    <Landline_ExtId action='del'>551534882809</Landline_ExtId> 
</Data> 

它給你下一個輸出:

<?xml version="1.0" encoding="UTF-8"?> 
<data> 
    <getMaxOld>551534882809</getMaxOld> 
    <getMinOld>551534882800</getMinOld> 
    <getMaxNew>771534777889</getMaxNew> 
    <getMinNew>771534777880</getMinNew> 
</data> 
+0

謝謝馬克。有效 – shaiksha