Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to delete a parent node and move the child node(s) up the tree

1,329 views
Skip to first unread message

CI

unread,
Apr 30, 2007, 1:29:42 PM4/30/07
to
Here is a simplified representation of my XML file

<root>
<paragraph>
<row id="1">
<childNode>
<grandchildNode>
....
</grandchildNOde>
</childNOde>
</row>

<row id="2">
<childNode>
<grandchildNode>
</grandchildNOde>
</childNOde>
</row>

<specialRow>
<row id="3">
<childNode>
<grandchildNode>
</grandchildNOde>
</childNOde>
</row>
</specialRow>

<row id="4">
<childNode>
<grandchildNode>
.....
</grandchildNOde>
</childNOde>
</row>
</paragraph>
</root>


I want to get rid off <specialRow> element and move all its child
nodes into its place.

Here is what the result tree should like:

<root>
<paragraph>
<row id="1">
<childNode>
<grandchildNode>
.....
</grandchildNOde>
</childNOde>
</row>

<row id="2">
<childNode>
<grandchildNode>
</grandchildNOde>
</childNOde>
</row>

<row id="3">
<childNode>
<grandchildNode>
</grandchildNOde>
</childNOde>
</row>

<row id="4">
<childNode>
<grandchildNode>
</grandchildNOde>
</childNOde>
</row>
</paragraph>
</root>

Thanks in advance

Michael

Martin Honnen

unread,
May 1, 2007, 7:35:03 AM5/1/07
to
CI wrote:

> I want to get rid off <specialRow> element and move all its child
> nodes into its place.

That is easy if you start with the identity transformation template and
add a template for specialRow that simply processes its child nodes:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="specialRow">
<xsl:apply-templates/>
</xsl:template>

</xsl:stylesheet>

If you want to correct the indentation then adding
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>
should help.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

CI

unread,
May 2, 2007, 1:38:00 AM5/2/07
to

Thank you very much Martin.

Michael

0 new messages