[Home] [By Thread] [By Date] [Recent Entries]
At 2004-06-29 00:07 +0100, Pedro Castro wrote:
I have this xml: ... And I want to transform it to this one: (The difference is that all the ccc elements, and it's children are removed from the location where they are and putted below the root element) This can be done in a straightforward fashion by modifying the identity transformation. I hope the example below helps. I've turned on indentation for illustration that may not apply in your case ... remember to remove the template at the end of the example that eats white-space-only text nodes. .............. Ken T:\ftemp>type pedro.xml
<root>
<aaa>
<bbb/>
<ccc/>
<bbb/>
</aaa>
<aaa>
<ccc>
<abc>test</abc>
</ccc>
<bbb/>
<bbb/>
</aaa>
</root>T:\ftemp>type pedro.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"><xsl:output indent="yes"/> <xsl:template match="root">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:copy-of select="//ccc"/><!--collect all ccc elements-->
</xsl:copy>
</xsl:template><xsl:template match="ccc"/><!--ignore ccc elements when found--> <xsl:template match="@*|node()"><!--identity for all other nodes-->
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template><!--this cleans up the output when using indent="yes"--> <xsl:template match="text()[not(normalize-space())]"/> </xsl:stylesheet>
T:\ftemp>saxon pedro.xml pedro.xsl
<?xml version="1.0" encoding="utf-8"?>
<root>
<aaa>
<bbb/>
<bbb/>
</aaa>
<aaa>
<bbb/>
<bbb/>
</aaa>
<ccc/>
<ccc><abc>test</abc> </ccc> </root> T:\ftemp>
|

Cart



