我从表中取的信息:如何排除XSLT中的字段?
<xsl:template match="table1">
<xsl:element name="ApplicantAddress">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
我要确保我没有从该表中包含的字段。那可能吗?
我从表中取的信息:如何排除XSLT中的字段?
<xsl:template match="table1">
<xsl:element name="ApplicantAddress">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
我要确保我没有从该表中包含的字段。那可能吗?
推风格:
<xsl:template match="table1">
<ApplicantAddress>
<xsl:apply-templates select="@* | node()[not(self::unwanted-element)]"/>
</ApplicantAddress>
</xsl:template>
拉风:
<xsl:template match="table1">
<ApplicantAddress>
<xsl:apply-templates select="@* | node()"/>
</ApplicantAddress>
</xsl:template>
<xsl:template match="table1/unwanted-element"/>
所以:
非常感谢。 – XstreamINsanity 2011-04-28 15:26:51
@XstreamINsanity:不客气。 – 2011-04-28 15:31:23
这种转变:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="table1">
<ApplicantAddress>
<xsl:apply-templates select="node()|@*"/>
</ApplicantAddress>
</xsl:template>
<xsl:template match="c"/>
</xsl:stylesheet>
当这个XML文档(你错过了提供应用):
<table1>
<a/>
<b/>
<c/>
<d/>
</table1>
产生想要的结果(元件b
未复制):
<ApplicantAddress>
<a />
<b />
<d />
</ApplicantAddress>
说明:使用并覆盖identity rule /模板是最根本的XSLT设计模式。这里我们用一个匹配c
的空体模板来覆盖身份规则,这可以确保这个元素被忽略(“删除”/未被复制)。
我想你的意思是元素'C'吧?这是否与其他答案不同,还是这番茄西红柿的东西? :) 谢谢。 – XstreamINsanity 2011-04-28 15:32:17
@XstreamINsanity:是的,我的意思是'c',我会编辑我的答案。我的答案与另一个不同,因为它提供了身份规则(以及要使用的完整样式表)。 @ Alejandro的回答假设身份规则在样式表中的某处。他甚至没有提到这个假设,只是将他的代码包装在一个'
好的,谢谢。我没有把所有的东西都放在答案中,只是为了确保我没有意外地放置任何专有信息。在我正在编辑的当前XSLT文件中(对XSLT文件是新的)我没有带区域,但是我有'
好问题,+1。查看我的答案,获取完全基于最基本且功能强大的XSLT设计模式的* complete *和short解决方案:使用和覆盖身份规则。还提供说明和链接。 – 2011-04-28 15:26:25