[英]XSLT compare two elements
我有這個 xml
<magazine>
...
<startPage>14</startPage>
<endPage>14</endPage>
...
</magazine>
<magazine>
...
<startPage>27</startPage>
<endPage>30</endPage>
...
</magazine>
我想比較startPage
和endPage
的值,看看這兩個頁面是否相等
IE
如果
startPage
=endPage
-> 做某事;如果沒有 -> 做其他事情
我應該如何在 XSLT 中解決這個問題?
您可以使用xsl:choose
在這里...
<xsl:template match="magazine">
<xsl:copy>
<xsl:choose>
<xsl:when test="startPage = endPage">
<xsl:text>EQUAL</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>NOT EQUAL</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
或者您可以將檢查放在模板匹配中,並為每個不同的邏輯設置單獨的模板
<xsl:template match="magazine[startPage = endPage]">
<xsl:copy>
<xsl:text>EQUAL</xsl:text>
</xsl:copy>
</xsl:template>
<xsl:template match="magazine">
<xsl:copy>
<xsl:text>NOT EQUAL</xsl:text>
</xsl:copy>
</xsl:template>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.