How to implement “if else if else” condition in XSLT

后端 未结 7 1982
心在旅途
心在旅途 2021-01-07 18:36

Is it possible to implement \"if else, if else\" in xsl? for example I have data:


    
        MAR111
          


        
相关标签:
7条回答
  • 2021-01-07 19:22

    Actually you can merge them together:

    <xsl:template match="/">
        <xsl:choose>
            <xsl:when test="/document/line/name='MEA111'">
                <xsl:apply-templates mode="MEA" select="/document"/>
            </xsl:when>
            <xsl:when test="/document/line/name='MPR111'">
                <xsl:apply-templates mode="MPR" select="/document"/>
            </xsl:when>
            <xsl:when test="/document/line/name='MAR111'">
                <xsl:apply-templates mode="MAR" select="/document"/>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
    

    EDIT: Petras, after your clarification, it seems that what you want is even easier:

    <xsl:template match="/">
        <xsl:if test="/document/line/name='MEA111'">
           <xsl:apply-templates mode="MEA" select="/document"/>
        </xsl:if>
        <xsl:if test="/document/line/name='MPR111'">
            <xsl:apply-templates mode="MPR" select="/document"/>
        </xsl:if>
        <xsl:if test="/document/line/name='MAR111'">
            <xsl:apply-templates mode="MAR" select="/document"/>
        </xsl:if>
    </xsl:template>
    
    0 讨论(0)
提交回复
热议问题