This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: difference between select="*" and select="node()"
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: Karthik Gurumurthy <karthikg at aztec dot soft dot net>
- Cc: xsl-list at lists dot mulberrytech dot com
- Date: Mon, 8 Apr 2002 12:44:36 +0100
- Subject: Re: [xsl] difference between select="*" and select="node()"
- Organization: Jeni Tennison Consulting Ltd
- References: <NEBBJNMDEKBIBCMCNMBDOEPIDIAA.karthikg@aztec.soft.net>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Karthik,
> it's behaving the same way for me :-(
> am using Oreilly's XSLT to learn XSLT.
> It says that node() selects the attribute as well in addition to the text
> nodes.
> But still my attribute values do not get printed.
> The book also mentions that attribute needs to be selected
> explicitly to apply the default rule for attributes.
> If node() does that then why does'nt it print?
When you do:
<xsl:apply-templates select="node()" />
it's short for:
<xsl:apply-templates select="child::node()" />
In other words, it selects all the *child* nodes of the current
element. Attributes don't count as children, so you don't select any
attributes.
To select attributes, you have to use the attribute axis:
<xsl:apply-templates select="attribute::node()" />
which is more commonly shortened to '@':
<xsl:apply-templates select="@node()" />
Usually you use the node test * rather than the node test node() to select attributes
<xsl:apply-templates select="@*" />
Technically, * matches the principal node type for whatever axis you
use. The only nodes that you can find along the attribute axis are
attributes, so doing @* is the same as doing @node().
If you want to select child nodes and attributes at the same time, use
the union operator:
<xsl:apply-templates select="@* | node()" />
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list