<content>
<A>111111</A>
<B>222222</B>
<C/>
<D/>
</content>
这里,很明显的可以看出<C/>,<D/>两个元素的值是空的。
那么我想问问,在XSL中如何判断这些元素是否为空?
用<xsl:if>行不?
那具体是用那个函数来判断元素呢?
---------------------------------------
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<xsl:for-each select="content/*">
<xsl:if test=".=''"><xsl:value-of select="name(.)"/>:空值</xsl:if>
<xsl:if test=".!=''"><xsl:value-of select="name(.)"/>:<xsl:value-of
select="."/></xsl:if><br/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
以上是xsl:if的用法,XSL中还有其它元素可用于判断。判断元素是否为空值也不仅以上一种方法。
----------------------------------------------------
比如 下面没有<C/>这个元素 可以判断吗?
<?xml version="1.0" encoding="GB2312"?>
<?xml-stylesheet type="text/xsl" href="2.xsl"?>
<content>
<A>111111</A>
<B>222222</B>
<D/>
</content>
---------------------------------------------------------
<xsl:when test="C">C元素存在!</xsl:when>
<xsl:otherwise>C元素不存在!</xsl:otherwise>
</xsl:choose>
<a id=1 name=asd add=sdrse />
<a id=2 name=dfgdsr add=sdfsdf />
<a id=8 name=aaewr add=dfsd />
<a id=3 name=aserawe add=fhdrty />
<a id=5 name=aea add=serawe />
这些节点,
请问我如何做才能从属性name中查找到只含有“ae“,并安id属性进行排序?
先谢谢了!
<xsl:sort select="id" order="ascending"/>
</xsl:for-each>