1

I am new to xpath .. I want to extract all the values of Age which is greater than 24 using for-each and if condition in xslt.

 <PriceBooking>
              <Guest>
              <GuestCount Age="24" Code="10" Quantity="1"/>
              <GuestCount Age="26" Code="10" Quantity="1"/>
              <GuestCount Age="3" Code="10" Quantity="1"/>
           </Guest>
    </PriceBooking>

So far I tried with the following :-

    <xsl:for-each select="PriceBooking/Guest">
    <xsl:choose>

    <xsl:when test="PriceBooking/Guest/GuestCount/@Age &gt; '28'">

    <Age><xsl:value-of select="PriceBooking/Guest/GuestCount/@Age"/></Age>
    </xsl:when>
<xsl:otherwise>
<Sid>Failed to load</Sid>
</xsl:otherwise>
</xsl:choose>

It's always going to otherwise condition .. Please help me with the xpath

sidaray
  • 25
  • 5

1 Answers1

0

Well you need to understand that the for-each changes the context node to be a Guest element and that way inside you need a relative path e.g.

<xsl:when test="GuestCount/@Age > 28">...</xsl:when>

But the sample you have posted has @Age values 24, 26, and 3 so the condition is never true.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110