1.xml
<users>
<user>
<id>1</id>
<userLogName>t1</userLogName>
<type>1</type>
<user>
<user>
<id>2</id>
<userLogName>t2</userLogName>
<type>2</type>
<user>
</users>  xsl中有一句是这样的
<xsl:for-each select="user[type='3']">
 </xsl:for-each>很明显,现在type=3是不存在的,有没有办法实现当不存在的时候显示
暂时没有数据。

解决方案 »

  1.   

    看看
    http://www.w3.org/TR/xslt#section-Conditional-Processing-with-xsl:choose
      

  2.   


    <xsl:choose></xsl:choose>
    兄弟是说的用这个吗?
    不知道是你没看懂我的意思,还是我没看懂你的意思,反正我没想到怎么解决这个问题。
    因为我这里的是
    <xsl:for-each select="user[type='3']">不知道兄弟是不是叫我换成下面的形式
    <xsl:choose>
    <xsl:when test="type='3'"></xsl:when>
    <xsl:choose>
    如果是这个形式好像问题并没有解决。
      

  3.   

    类试这种?
    <xsl:when test="count(/NewDataSet/Table) = 0">
    找不到相关分类
    </xsl:when>
    <xsl:otherwise><xsl:for-each select="/NewDataSet/Table">
      

  4.   

    例子里面用到了变量,没试过,觉得应该可行 <xsl:variable name="level" select="count(ancestor::orderedlist) mod 3"/>
          <xsl:choose>
            <xsl:when test='$level=1'>
              <xsl:number format="i"/>
            </xsl:when>
            <xsl:when test='$level=2'>
              <xsl:number format="a"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:number format="1"/>
            </xsl:otherwise>
          </xsl:choose>
      

  5.   

     谢谢
    liuchaolin和showenxxx
    综合你们的回复
      

  6.   

     解决了。
      先在常量里求出条数,我开始的思路是先for-each 所以行不通
    <xsl:variable name="level" select="count(user[type='3'])"/>
      <xsl:choose>
      <xsl:when test='$level!=0'>
         <xsl:for-each select="user[type='3']">
         </xsl:for-each>
      </xsl:when> 
      <xsl:otherwise>
       这里打印没有记录的提示
      </xsl:otherwise>
      </xsl:choose>
      

  7.   


        <xsl:when   test= 'count(user[type= '3 '])!=0 '> 
    这样写,估计也能行得通。