[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Select entire XML doc

Subject: RE: Select entire XML doc
From: "Martinez, Brian" <brian.martinez@xxxxxxxx>
Date: Mon, 3 Mar 2003 17:03:04 -0700
brian martinez
> From: Lars Huttar [mailto:lars_huttar@xxxxxxx]
> Sent: Monday, March 03, 2003 4:05 PM
> Subject: RE:  Select entire XML doc
> [Brian Martinez wrote:]
> > > > <xsl:template match="/">
> > > >   <textarea>
> > > >     <xsl:copy-of select="*"/>
> > > >   </textarea>
> > > > </xsl:template>
> > >
> > > From: Lars Huttar
> > > 
> > > Just out of curiosity, and because I'm learning:
> > > Wouldn't the above copy-of fail to copy any non-element 
> > > children of the
> > > root node?  E.g. comments and PI's...
> > > (He did say "the entire XML document.")
> > 
> > No.  If the comments and PIs (by that I assume you mean processing
> > instructions) are children of the root or context node, 
> > xsl:copy-of will
> > write them to the result tree.
> > 
> > cheers,
> > b.
> What I meant was that because your <xsl:copy-of> used select="*",
> it would only operate on element children of the root node.
> So comments/PIs would only be copied if they were descendants
> of the document node, not if they were children of "/".

You're right and I'm right.  ;-)

But I made the common mistake of confusing "document element" (or "root
element," as it's also sometimes called) with the "root node" as it applies
to XPath.  The root node of a well-formed XML document can have exactly one
document element.  In XPath, selecting the "root node" (which is often used
interchangeably with root or document element) means selecting the root node
containing the specified context node.  So when you write

<xsl:template match="/">

what you're saying is "select the root node of the document *and* the
document element."  You could also do:

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

with the exact same results.  Remember that the transformation works on a
parsed XML input tree--not the raw document.  So any child of the root node
that isn't an element is removed, and if there is more than one child
element of the root node, the document is rejected by the parser as being
malformed XML.


| brian martinez                              brian.martinez@xxxxxxxx |
| senior gui programmer                                  303.708.7248 |
| trip network, inc.                                 fax 303.790.9350 |
| 6436 s. racine cir.                             englewood, co 80111 |
| http://www.cheaptickets.com/                   http://www.trip.com/ |

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.