[英]How to get the value of a node using for each and if in xpath
我是xpath的新手。我想使用for-each和if條件在xslt中提取大於24的Age的所有值。
<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>
到目前為止,我嘗試了以下方法:
<xsl:for-each select="PriceBooking/Guest">
<xsl:choose>
<xsl:when test="PriceBooking/Guest/GuestCount/@Age > '28'">
<Age><xsl:value-of select="PriceBooking/Guest/GuestCount/@Age"/></Age>
</xsl:when>
<xsl:otherwise>
<Sid>Failed to load</Sid>
</xsl:otherwise>
</xsl:choose>
否則總是會出現問題..請幫助我使用xpath
那么,您需要了解for-each
將上下文節點更改為Guest
元素,並且內部需要一種相對路徑,例如
<xsl:when test="GuestCount/@Age > 28">...</xsl:when>
但是您發布的樣本的@Age
值分別為24、26和3,因此該條件永遠不會成立。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.