This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: difference between select="*" and select="node()"


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]