[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: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Tue, 4 Mar 2003 13:57:22 -0600
xsl copy entire xml
> > > > > <xsl:template match="/">
> > > > >   <textarea>
> > > > >     <xsl:copy-of select="*"/>
> > > > >   </textarea>
> > > > > </xsl:template>
> > > >
...
> > 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.

OK, that clears things up a little. :-)

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

Really?  I thought <xsl:template match="/"> would match only the root
node ("/"), and if you want to do anything with the document element
you refer to it with the (implicit) child axis (e.g. "*" or "mydoc"):

  <xsl:template match="/">
    <xsl:for-each select="*">
	 <p><xsl:value-of select="name()"/></p>
    </xsl:for-each>
  </xsl:template>

which prints the name of the document element, not its children.

>  You could also do:
>
> <xsl:template match="/*">
>   <xsl:copy-of select="."/>
> </xsl:template>
>
> with the exact same results.

The same results as

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

but not the same results as

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

right?

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

Are you sure?  Kay p. 63 seems to disagree:
[speaking of "The Tree Model", not of the raw XML text]
"For a *well-formed document* the children of the root
node will be the document element *plus any comments or processing
instructions* that come before or after the document element."
(emphasis mine)

Lars


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.