xsl-list
[Top] [All Lists]

Re: [xsl] How to duplicate an entire subtree

2008-12-26 19:57:15
At 2008-12-27 01:17 +0100, nick public wrote:
I'm using an XSL processor ver. 1 by Microsoft

I'm using Microsoft in the work below, and it doesn't preserve the input text nodes.

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.

Use <xsl:copy-of/>

An example can be this in which I want to duplicate the <book> node and subs:
...
The output have to be like this:
...
I tried this script (and several variants of it):
...
The disconcerting thing is that I'm able to achieve just the text
elements whitout the XML structure.

<xsl:copy-of preserves all nodes addressed, any attached nodes, and all descendants and their attached nodes.

Have a look to the output:
...
Who can help me, please?

I hope the example below helps.

. . . . . . . . Ken


t:\ftemp>type nick.xml
<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>

t:\ftemp>call xslt-msxsl nick.xml nick.xsl nick.out

t:\ftemp>type nick.out
<?xml version="1.0" encoding="UTF-16"?>
<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>

t:\ftemp>type nick.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">

<xsl:output indent="yes"/>

<xsl:template match="book">
  <xsl:copy-of select="."/>
  <xsl:copy-of select="."/>
</xsl:template>

<xsl:template match="@*|node()"><!--identity for all other nodes-->
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>


t:\ftemp>echo Done!
Done!



--
Upcoming XSLT/XSL-FO, UBL and code list hands-on training classes:
:  Sydney, AU 2009-01/02; Brussels, BE 2009-03; Prague, CZ 2009-03
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video sample lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg
Video course overview:  http://www.youtube.com/watch?v=VTiodiij6gE
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>