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

RE: name() of root element

Subject: RE: name() of root element
From: Stuart Brown <sbrown@xxxxxxxxxxx>
Date: Tue, 1 Apr 2003 16:42:38 +0100
xpath root name
Hi Joseph,

> Why does this not select the name of the root *element* but 
> instead gives me the text value of that element, i.e., the 
> concatenated text values of every element in my document?
> 
>     <xsl:template match="/" >
>         <xsl:value-of select="(/node()[1])[name()]" />
>         <xsl:apply-templates />
>     </xsl:template>

This returns the value of the first node child of the root node (see below),
if it has a name (which, as an element, it does), which is its text content.
Remember that anything within [] is a predicate and is used simply to filter
the previous XPath step.

> When I try select="/name()" (and variations thereof) I get 
> error messages from the xsl processor.

The XPath "/" does not return the document element (the element in which all
others are contained), but the root node, which is an abstract higher-level
container which contains everything (including any comments, etc., which do
not fall within the document element). It has no name, it just is
(nominalist metaphysics notwithstanding). If you want the name of the
document element, you want the first (and only) element child of "/"; that
is <xsl:value-of select="name(/*)"/>.

The fact that at the start of an XPath "/" means the root node, whereas
anywhere else it is the step delimiter can be confusing.

Hope that helps,

Stuart

 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.