XSL:声明变量和 If 语句和显示文本



我正在尝试在 XSL 中构建一个变量,然后使用 IF 语句根据值添加或不添加文本。没有任何错误只是不起作用:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="Association">
<xsl:variable name="asn" select="asn_name"/>
<!--MAH 9/25/2018 -->
<div style="float:left;">
<p class="span2">           
<img src="images/aha/logo/{asn_code}.gif"/>
</p>
<p class="span7">
<xsl:if asn="AHE">Professional Membership Groups</xsl:if>
<xsl:if asn="ACHI">Other Individual Membership Organizations</xsl:if>
<b><xsl:value-of select="asn_name" disable-output-escaping="yes" /> (<xsl:value-of select="asn_code" disable-output-escaping="yes" />)</b>
<br /><br />
<xsl:value-of select="asn_eweb_description_ext" />
<br /><br />
Click <a href="dynamicpage.aspx?webcode=AHAMembershipList&amp;asn_key={asn_key}">here</a> to learn more about the membership options.
<br /><br />
</p>
</div>
<!-- End MAH 9/26/2018-->
</xsl:template>
</xsl:stylesheet>

变量:

<xsl:variable name="asn" select="asn_name"/>

如果语句当前不起作用:

<xsl:if asn="AHE">Professional Membership Groups</xsl:if>
<xsl:if asn="ACHI">Other Individual Membership Organizations</xsl:if>

你可能想要如下的东西:

<xsl:if test="asn = 'AHE'">
<xsl:text>Professional Membership Groups</xsl:text>
</xsl:if>

或者,如果要考虑多个可能的值,可以尝试以下操作:

<xsl:choose> 
<xsl:when test="asn = 'AHE'"> 
<xsl:text>Professional Membership Groups</xsl:text> 
</xsl:when> 
<xsl:when test="asn = 'ACHI'"> 
<xsl:text>Other Individual Membership Organizations</xsl:text> 
</xsl:when> 
<xsl:otherwise> 
<xsl:text>Some other response could go here</xsl:text> 
</xsl:otherwise> 
</xsl:choose> 

我们使用以下代码让它工作:

<xsl:template match="/">
<h3>Professional Membership Groups</h3><br />
<xsl:for-each select="associations/association[asn_groups=0]">
<div>
<div class="span2"><img src="images/aha/logo/{asn_code}.gif"/></div>
<div class="span9">
<h4><xsl:value-of select="asn_name" disable-output-escaping="yes" /> (<xsl:value-of select="asn_code" disable-output-escaping="yes" />)</h4>
<p><xsl:value-of select="asn_eweb_description_ext" /></p>
<p>Click <a href="dynamicpage.aspx?webcode=AHAMembershipList&amp;asn_key={asn_key}">here</a> to learn more about the membership options.</p><br /><br />
</div>
</div>
</xsl:for-each>
<h3>Other Individual Membership Organizations</h3><br />
<xsl:for-each select="associations/association[asn_groups=1]">
<div>
<div class="span2"><img src="images/aha/logo/{asn_code}.gif"/></div>
<div class="span9">
<h4><xsl:value-of select="asn_name" disable-output-escaping="yes" /> (<xsl:value-of select="asn_code" disable-output-escaping="yes" />)</h4>
<p><xsl:value-of select="asn_eweb_description_ext" /></p>
<p>Click <a href="dynamicpage.aspx?webcode=AHAMembershipList&amp;asn_key={asn_key}">here</a> to learn more about the membership options.</p><br /><br />
</div>
</div>
</xsl:for-each>

最新更新