This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Transforming node to different location in output
- To: "'xsl-list at mulberrytech dot com'" <xsl-list at mulberrytech dot com>
- Subject: RE: Transforming node to different location in output
- From: Kay Michael <Michael dot Kay at icl dot com>
- Date: Wed, 19 Apr 2000 18:14:18 +0100
- Reply-To: xsl-list at mulberrytech dot com
> Can anyone help me figure out how to transform one
> node to a different location in the output
> Example:
> Input:
> <?xml version="1.0"?>
> <document>
> <tag1>
> <element1>data</element1>
> <element2>data</element2>
> </tag1>
> <tag2>
> <element1>data</element1>
> <element2>data</element2>
> </tag2>
> <tag3>
> <element1>data</element1>
> <element2>data</element2>
> </tag3>
> </document>
>
> Output:
> <?xml
>
> The output that I would like to get might be something
> like this:
>
> <?xml version="1.0" encoding="utf-8"?>
> <document>
> <tag2>
> <element1>data</element1>
> <element2>data</element2>
> </tag2>
> <tag3>
> <element1>data</element1>
> <element2>data</element2>
> <newtag1>
> <newelement1>data</newelement1>
> <newelement2>data</newelement2>
> </newtag1>
> </tag3>
> </document>
>
Hard to generalise from one example. You could achieve this particular
transformation by:
<xsl:template match="document">
<xsl:copy>
<xsl:copy-of select="tag2"/>
<xsl:copy select="tag3">
<xsl:copy-of select="tag3/*"/>
<xsl:apply-templates select="tag1"/>
</xsl:copy>
</xsl:copy>
</xsl:template>
<xsl:template match="tag1">
<newtag1><xsl:apply-templates/></newtag1>
</xsl:template>
<xsl:template match="element1">
<newelement1><xsl:apply-templates/></newelement1>
</xsl:template>
general principle: xsl:copy-of for a deep copy, xsl:copy for a shallow copy,
xsl:apply-templates for a transformation.
Mike Kay
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list