如果空的话我可以测试这样的节点吗?
<Address> <Street></Street> <Building></Building> <Postcode></Postcode> <Town></Town> <State></State> <Country></Country> </Address>
您可以通过以下方式测试节点及其子节点是否为空:
<xsl:if test="normalize-space(.)=''">All nodes empty: true
</xsl:if>
或者,您可以通过以下方式测试它是否具有空节点:
<xsl:if test="normalize-space(*)=''">Contains an empty node: true
</xsl:if>
当您的输入XML运行此样式表时:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output omit-xml-declaration="yes"/> <xsl:template match="Address"> <xsl:if test="normalize-space(.)=''">All nodes empty: true
</xsl:if> <xsl:if test="normalize-space(*)=''">Contains an empty node: true
</xsl:if> </xsl:template> </xsl:stylesheet>
它会产生:
All nodes empty: true Contains an empty node: true
在action中查看 .
1 回答
您可以通过以下方式测试节点及其子节点是否为空:
或者,您可以通过以下方式测试它是否具有空节点:
当您的输入XML运行此样式表时:
它会产生:
在action中查看 .