【问题标题】:XSL Displaying a message to the user if an element's count is 0XSL 如果元素的计数为 0,则向用户显示消息
【发布时间】:2014-12-13 15:14:28
【问题描述】:

我有一个名为 channels 的元素,它已在 XML 文件中指定了值。我想要做的是,当 XML 文件没有任何通道时,向用户显示一条消息。 这是我的代码。

    <h2>Channels Subscription:</h2>
    <xsl:template>
    <xsl:if test="  <xsl:value-of select="count(subscription/channels)"/>
 ==0)">
 <p>You have no channels</p>
    </xsl:if>

        </xsl:template>

上面的代码不起作用 之后是表格的另一部分..当用户有一个或更多频道时,它会显示

<xsl:for-each select="subscription/channels">

    <xsl:choose>
<xsl:when test="@favourite='true'">


                <h3 >Channel Name:</h3> <h3 style="color:green;"><xsl:value-of select="@name"/></h3>

                </xsl:when>
<xsl:otherwise>
    <h3 >Channel Name: </h3><h3 style="color:black; "><xsl:value-of select="@name"/></h3>
</xsl:otherwise>
</xsl:choose>
                    <p>ID: <xsl:value-of select="@id"/></p>
                    <h3>Programs:</h3>
                    <xsl:for-each select="programs">
    <table ID="gradient-style">
        <tbody>
            <tr>
                <th>Program Name:</th>
                <td><xsl:value-of select="name"/></td>
            </tr>
            <tr>
                <th>Broadcast Time:</th>
                <td>
                    <xsl:value-of select="@broadcastFrequency"/> at <xsl:value-of select="@broadcastTime"/> 
                </td>
            </tr>
            <tr>
                <th>Description:</th>
                <td><xsl:value-of select="description"/></td>
            </tr>
        </tbody>
    </table>    
        </xsl:for-each>

它可以工作

【问题讨论】:

    标签: html xml xslt web xsd


    【解决方案1】:

    你的xsl:if错了,应该是这样的

    <xsl:if test="count(subscription/channels) = 0">
       <p>You have no channels</p>
    </xsl:if>
    

    供参考:http://www.w3.org/TR/xslt#section-Conditional-Processing-with-xsl%3aif

    【讨论】:

      猜你喜欢
      • 2016-12-19
      • 1970-01-01
      • 1970-01-01
      • 2013-05-22
      • 1970-01-01
      • 2017-09-28
      • 2022-12-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多