有个问题,查了下xsl的文件,想问下如何判断获取的值中是否包含某一元素。
代码: <xsl:for-each select="/root/tbody/tr[td[1] &gt; '1' ]">
    <tr>
<xsl:for-each select="td[position() &gt; 2 ]">
<xsl:variable name="colNum" select="td[position()]"/>
<xsl:choose>
<xsl:when test="position()=1">
<td>
   <xsl:value-of select="."/>
</td>
             </xsl:when>
<xsl:when test="position()&gt;3">
---在这里我想加个判断,就是如果说这列的数据中如果包含百分号的话,就原样输出,如果没有的话,就执行下边的这个format—number
<td align="right">
<xsl:value-of select="format-number(.,'#,##0.00')"/>
</td>
</xsl:when>
<xsl:otherwise>
   <td>
<xsl:value-of select="."/>
</td>
</xsl:otherwise>
</xsl:choose>
   </xsl:for-each>
</tr>
</xsl:for-each>问下这块儿应该怎么写,以前没有接触过,不太会写这里

解决方案 »

  1.   

    想问下这么写哪儿有问题,页面儿没有反应
    <xsl:for-each select="/root/tbody/tr[td[1] &gt; '1' ]">
    <tr>
    <xsl:for-each select="td[position() &gt; 2 ]">

    <xsl:choose>
    <xsl:when test="position()=1">
    <td>
    <xsl:value-of select="."/>
    </td>
    </xsl:when>
    <xsl:when test="position()&gt;3">
        <xsl:variable name="isPercent" select="contains(.,'%')"/>
    <xsl:when test="$isPercent=true">
    <td align="right">
    <xsl:value-of select="."/>
    </td>
    </xsl:when>
    <xsl:otherwise>
    <td>
    <xsl:value-of select="."/>
    </td>
    </xsl:otherwise>
    </xsl:when>
    <xsl:otherwise>
    <td>
    <xsl:value-of select="."/>
    </td>
    </xsl:otherwise>
    </xsl:choose>
       </xsl:for-each>
    </tr>
    </xsl:for-each>
      

  2.   

    看着有点儿乱,不过提示你几个注意的问题,你自己去比对下,首先每一个when的外边都要用<xsl:choose>包裹,其次看你的when写的有地方看着好像不大对,你再查下