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

Re: Position() in apply-templates

Subject: Re: Position() in apply-templates
From: Geert Bormans <geert@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 02 Apr 2014 01:19:57 +0200
Re:  Position() in apply-templates
Hi David,

There is no conflict between what the references tell you

To quote the example from Jeni Tennison's post
<xsl:template match="/">
  <xsl:apply-templates select="r/a">
    <xsl:sort data-type="number" select="@at"/>
    <xsl:with-param name="p" select="position()"/>
  </xsl:apply-templates>
</xsl:template>

What you read in Michael Kay's book is that the nodes in the select of the apply-templates
"r/a" are selected, ordered according to the sort statement(s) and then numbered.


The position() inside the template that will eventually pick up the nodes will have that number as its value

<xsl:template match="r/a">
<xsl:value-of select="position()"/> <= here is where the numbering of the nodes plays
</xsl:template>


What Jeni Tennison says is that the position() inside the body of the apply-templates
eg here:
<xsl:with-param name="p" select="position()"/>
will get its value from the context of the template, not from the node numbering in the select.


apply-templates will not change the context,
for-each on the other hand will create a new context

I hope that helps

Geert





At 23:18 1/04/2014, you wrote:
Can someone clarify the meaning of "position()" in apply-templates.

According to Michael's Kay's 4th edition,

"When <xsl:apply-templates> or <xsl:for-each> is called to process a
sequence of nodes, the nodes ar enumbers 1 to N in their sorted order,
and while each node is being processed. the context position is the
number assigned to that node."

But I found a 2001 post indicating that, within an
<xsl:apply-templates> instruction *itself* the context position is
just the context position of the current node (_not_ the nodes being
selected by the select attribute of <xsl:apply-templates>). That post
is here=http://www.stylusstudio.com/xsllist/200105/post90830.html

My question is "When the "number assigned to that node" (as referenced
in Kay) is considered the context position? :

A. In the predicate of the select attribute of the
<xsl:apply-templates> instruction?
B. In the select attribute of any <xsl:with-param> instructions inside
the <xsl:apply-templates> instruction?
C. In the body of the <xsl:template> called by the
<xsl:apply-templates> instruction?


-David




--

"A false conclusion, once arrived at and widely accepted is not
dislodged easily, and the less it is understood, the more tenaciously
it is held." - Cantor's Law of Preservation of Ignorance.

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.