Two possible solutions using identity templates. The first one uses a
dedicated mode for the nested items:
<xsl:template match="List">
<xsl:copy>
<xsl:apply-templates select=".//Item"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Item">
<xsl:copy>
<xsl:apply-templates mode="suppress-item"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Item" mode="suppress-item" />
<xsl:template match="* | @*" mode="#all">
<xsl:copy>
<xsl:apply-templates select="@*, node()" mode="#current"/>
</xsl:copy>
</xsl:template>
Second solution, single mode, for-each, identity template:
<xsl:template match="List">
<xsl:copy>
<xsl:for-each select=".//Item">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template match="Item" />
<xsl:template match="* | @*">
<xsl:copy>
<xsl:apply-templates select="@*, node()" mode="#current"/>
</xsl:copy>
</xsl:template>
Both won’t leave an empty ElementA though because of the contained text
nodes.
And both won’t process nested Lists in Items.
Gerrit
On 2012-09-04 23:56, Mark wrote:
I have XML consisting of <Item> elements that have nested <Item>
elements at various depths within the tree, in its simplest form
something like:
<List>
<Item>
<ElementA>
<Item>
<ElementB/>
</Item>
</ElementA>
</Item>
</List>
That I want to render as:
<List>
<Item>
<ElementA/>
</Item>
<Item>
<ElementB/>
</Item>
</List>
Is there a general technique I can use to remove nested <Item> elements
whatever their depth and place all <Item> elements at the same level
within the <List>?
Thanks,
Mark
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--
Gerrit Imsieke
Geschäftsführer / Managing Director
le-tex publishing services GmbH
Weissenfelser Str. 84, 04229 Leipzig, Germany
Phone +49 341 355356 110, Fax +49 341 355356 510
gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de, http://www.le-tex.de
Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930
Geschäftsführer: Gerrit Imsieke, Svea Jelonek,
Thomas Schmidt, Dr. Reinhard Vöckler
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--