首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

<xsl:for-each>是否存在的有关问题

2012-02-13 
xsl:for-each是否存在的问题1.xmlusersuserid1/iduserLogNamet1/userLogNametype1/type

<xsl:for-each>是否存在的问题
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是不存在的,有没有办法实现当不存在的时候显示
暂时没有数据。





[解决办法]
你要判断单一节点,就不能使用for-each了,直接判断即可
<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="users">
<xsl:if test="not(user[type='3'])">
None
</xsl:if>
</xsl:template>

</xsl:stylesheet>


for-each筛选的都是存在的

热点排行