|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Transforming node to different location in output
Mike,
Thanks for your help! I think I now have a better
understanding of when to use copy, copy-of and
apply-templates.
I was wondering if you might be able to provide some
additional guidance. I am trying to do a
transformation (slightly different from the one
described in my previous post) by renaming a node and
its children and moving this newly named node to a
particular location in the output. I know the element
that will precede the intended output location, but
the elements before this element can vary. The
following XSL (I modified slightly the XSL you
provided) renames and moves the node as desired, but I
am looking to change the <xsl:copy-of select="tag2"/>
to something more generic, so that I can copy
everything (except tag1) as is and then once I have
copied tag2 to the output, tag1 will be transformed
through a template. The copying will then resume
generically for the rest of the document, as the
subsequent elements may vary.
<xsl:template match="document">
<xsl:copy>
<xsl:copy-of select="tag2"/>
<xsl:apply-templates select="tag1"/>
<xsl:copy-of select="tag3"/>
</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>
<xsl:template match="element2">
<newelement2><xsl:apply-templates/></newelement2>
</xsl:template>
I would like to take this input:
<document>
<tag1>
<element1>tag1data1</element1>
<element2>tag1data2</element2>
</tag1>
<tag15>
<element1>tag15data1</element1>
<element2>tag15data2</element2>
</tag15>
<tag2>
<element1>tag2data1</element1>
<element2>tag2data2</element2>
</tag2>
<tag3>
<element1>tag3data1</element1>
<element2>tag3data2</element2>
</tag3>
</document>
and create the output:
<document>
<tag15>
<element1>tag15data1</element1>
<element2>tag15data2</element2>
</tag15>
<tag2>
<element1>tag2data1</element1>
<element2>tag2data2</element2>
</tag2>
<newtag1>
<newelement1>tag1data1</newelement1>
<newelement2>tag1data2</newelement2>
</newtag1>
<tag3>
<element1>tag3data1</element1>
<element2>tag3data2</element2>
</tag3>
</document>
Any help is much appreciated.
Jonathan
__________________________________________________
Do You Yahoo!?
Send online invitations with Yahoo! Invites.
http://invites.yahoo.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








