xsl-list
[Top] [All Lists]

RE: RE: [xsl] How to duplicate an entire subtree

2008-12-28 13:10:23
At 2008-12-28 09:38 +0100, nick public wrote:
Ken,
I thank you very much for your help.

> t:\ftemp>call xslt-msxsl nick.xml nick.xsl nick.out
Where I can find xslt-msxsl tool?

That's just an adaptation of a post someone made long ago on the mail lists. I make a copy available to my XSLT students and on my web site:

  http://www.cranesoftwrights.com/resources/#debugmsxml

As I wrote in my thread, I'm not able to produce an XML output from my XSLT.

It is XML that I see output using your stylesheet, only there aren't any elements in the XML. Your stylesheet creates an external parsed XML entity of only text. That is shown by the presence of the XML declaration at the start of the file.

I notice that this happen not just for this example but for previous
XSLT scripts too.

There is something wrong?

Sorry, I didn't explain what was happening in your stylesheet:

<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 second template above never fires because the priority of the first template will "catch" the <book> element. In that first template rule all you are doing is pushing the child nodes of <book> at your stylesheet, and you are not providing any template rules for it.

This means that only the built-in template rules defined by XSLT will be used for your entire structure, and twice for the children of book. Since the built-in template rules will only preserve the values of text and attribute nodes, only the text ends up in your result:

t:\ftemp>xslt nick.xml nick-orig.xsl con
<?xml version="1.0" encoding="utf-8"?>

              Gambardella, Matthew
              XML Developer's Guide
              Computer
              44.95
              2000-10-01
              An in-depth look at creating applications
with XML.

              Gambardella, Matthew
              XML Developer's Guide
              Computer
              44.95
              2000-10-01
              An in-depth look at creating applications
with XML.


t:\ftemp>

Remember that in XSLT only one template rule fires whenever you push a node at your stylesheets. You have two template rules for the same node, and only the template rule with the highest priority will handle the node.

I hope this helps.

. . . . . . . . . . . . Ken

p.s. I note your time zone is central Europe ... I'm running an in-depth, hands-on publicly-subscribed XSLT class in Prague in March as a pre-conference tutorial to the XML Prague'2009 conference:

  http://www.xmlprague.cz/index.html


--
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>