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

Re: node() as pattern

Subject: Re: node() as pattern
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 12 Jun 2002 15:08:50 +0100
child node pattern
Hi Dave,

> Anyone got a nice clear description of what's happening
> with such as 
>
> match='/node()[2]/node()[8]/node()[2]/node()[8]/node()[7]'
>
> please?

This matches the 7th child node of the 8th child node of the 2nd child
node of the 8th child node of the 2nd child node of the root node. So
it'll only match anything if the root node has at least two children,
the second of which has at least 8 children, the 8th of which has at
least 2 children, the 2nd of which has at least 8 children, the 8th of
which has at least 7 children.

Assuming that you're dealing with a well-formed XML document,
containing only elements (no processing instructions, comments or
text), it won't match anything since the root node doesn't have a
second child.

Your other example was:

<doc>
  <nd1>
    <nd2>..</nd2>
    <nd3/>
  </nd1>
</doc>

(well, I assume that's what you meant -- you had an extra closing tag
for the nd1 element that didn't fit) with:

<xsl:template match='/node()[1]/node()[2]'>
  ...
</xsl:template>

This matches the second child node of the first child node of the root
node. The first child node of the root node is the doc element, but
that only has one child node (the nd1 element), so again, the template
doesn't match any nodes.

Perhaps it would help you to imagine the nodes numbered by their
position within their parent as follows:

<doc node="1">
  <nd1 node="1">
    <nd2 node="1">..</nd2>
    <nd3 node="2" />
  </nd1>
</doc>

So templates that would match these nodes would be:

  /node()[1]                       (matches doc)
  /node()[1]/node()[1]             (matches nd1)
  /node()[1]/node()[1]/node()[1]   (matches nd2)
  /node()[1]/node()[1]/node()[2]   (matches nd3)

Given that you don't have any processing instructions, comments or
text nodes, using node() is exactly the same as using *.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread
  • node() as pattern
    • DPawson - Wed, 12 Jun 2002 09:47:23 -0400 (EDT)
      • Jeni Tennison - Wed, 12 Jun 2002 10:18:01 -0400 (EDT) <=
      • Wendell Piez - Wed, 12 Jun 2002 11:41:03 -0400 (EDT)
      • Michael Kay - Wed, 12 Jun 2002 12:01:56 -0400 (EDT)
      • <Possible follow-ups>
      • DPawson - Wed, 12 Jun 2002 10:47:58 -0400 (EDT)
      • DPawson - Thu, 13 Jun 2002 03:56:15 -0400 (EDT)

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.