Subject: RE: [xsl] How to duplicate an entire subtree From: Raymond Bissonnette <raybiss@xxxxxxxxxxx> Date: Fri, 26 Dec 2008 19:53:20 -0500 |
Hi Nick, Try this one: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <!-- catalog template --> <xsl:template match="catalog"> <xsl:copy> <xsl:apply-templates select="book"/> </xsl:copy> </xsl:template> <!-- book template --> <xsl:template match="book"> <xsl:copy> <xsl:apply-templates select="node()|@*" mode="import"/> </xsl:copy> <xsl:copy> <xsl:apply-templates select="node()|@*" mode="import"/> </xsl:copy> </xsl:template> <!-- indetity transform --> <xsl:template match="@*|node()" mode="import" priority="-1"> <xsl:copy> <xsl:apply-templates select="@*|node()" mode="import"/> </xsl:copy> </xsl:template> </xsl:stylesheet> Hope this helps, Raymond -----Original Message----- From: nick public [mailto:nickpubl@xxxxxxxxx] Sent: Friday, December 26, 2008 7:17 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] How to duplicate an entire subtree Hi experts. I'm using an XSL processor ver. 1 by Microsoft and I have the following URGENT problem. I need to produce an XML output containing the duplication of a (very complex) node; not just the text elements but element name and attribute(s) too. An example can be this in which I want to duplicate the <book> node and subs: ========================= <catalog> <book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book> </catalog> ========================= The output have to be like this: ========================= <catalog> <book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book> <book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book> </catalog> ========================= I tried this script (and several variants of it): ========================= <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:output method='xml' indent='yes'/> <xsl:template match='catalog/book'> <xsl:apply-templates/> <xsl:apply-templates/> </xsl:template> <xsl:template match='book'> <xsl:copy> <xsl:apply-templates select='@*|node()'/> </xsl:copy> </xsl:template> </xsl:stylesheet> ========================= The disconcerting thing is that I'm able to achieve just the text elements whitout the XML structure. Have a look to the output: ========================= Gambardella, MatthewXML Developer's GuideComputer44.952000-10-01An in-depth look at creating applications with XML. Gambardella, MatthewXML Developer's GuideComputer44.952000-10-01An in-depth look at creating applications with XML. ========================= Who can help me, please? Ciao. Nicola
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] How to duplicate an entire su, nick public | Thread | Re: [xsl] How to duplicate an entir, G. Ken Holman |
[xsl] How to duplicate an entire su, nick public | Date | Re: [xsl] How to duplicate an entir, G. Ken Holman |
Month |