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

时间:2018-09-27 16:49:58

标签: html xslt-1.0

我正在尝试在XSL中构建变量,然后使用IF语句添加文本还是不基于值。没有任何错误就是行不通的:

public class Key implements Serializable {
    @Field(order = 1)
    private final @NotNull String region;
    @Field(value = "id", order = 2)
    private final @NotNull String id;
    public Key(@NotNull String region, @NotNull String id) {
        this.region = region;
        this.id = id;
    }
}

变量:

{ "_id" : { "region" : "us_west", "id" : "12345" } }

如果当前语句不起作用:

    <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>

2 个答案:

答案 0 :(得分:0)

您可能想要以下内容:

<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> 

答案 1 :(得分:0)

我们使用以下代码使其工作:

    <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>