我创建了一个查找节点并删除它的XSLT样式表。这很好。我现在要检查某个节点是否存在,然后删除该节点(如果它存在)。如何正确使用XSLT if语句?
所以我试图添加if语句,这就是被我碰到了以下错误:
compilation error: file dt.xls line 10 element template
element template only allowed as child of stylesheet
我想我明白了错误,但不知道如何避开它。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="Ad">
<xsl:template match="node()|@*">
<xsl:if test="name-ad-size">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:if>
</xsl:template>
</xsl:template>
<xsl:template match="phy-ad-width"/>
<xsl:strip-space elements="*"/>
<xsl:preserve-space elements="codeListing sampleOutput"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
我修正了您的格式,但您的XSL无效,因为您无法在模板中放置一个' 2010-08-04 16:32:48
@Jim:aha,我只看到了'xsl:if',所以我猜想剩下的问题。其余的都没有了,因为它不在代码块中。啊,无论如何,答案应该保持不变;-) – Abel 2010-08-04 16:36:48