xsl-list
[Top] [All Lists]

RE: [xsl] position of the parents node -> XSLT1.1

2006-05-09 05:18:37
You're using the term "position of a node" as if we know what you mean by
the concept. Your explanation:

I need to know the position if the parents node of the 
current node in its parent node.

is a little confused!

Sometimes people use "the position of a node" to mean the number of
preceding siblings (nodes or elements) of the node (plus one, perhaps). Is
that your meaning? If so, it's quite unrelated to the XPath position()
function.

The simplest way to find the position of a node, in this sense, is
count(preceding-sibling::*) or count(preceding-sibling::node()), depending
on which of the two definitions you are using. You can also use
<xsl:number/>.

Michael Kay
http://www.saxonica.com/ 

-----Original Message-----
From: news(_at_)swisslab(_dot_)de [mailto:news(_at_)swisslab(_dot_)de] 
Sent: 09 May 2006 13:13
To: 'xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com'
Subject: [xsl] position of the parents node -> XSLT1.1

Hello List,

I'm perfomring an XML to XML transformation. Therefore I m 
using a template by Michael Kay's book "XSLT 2nd Edition" page 194.

<xsl:template match="@*|node()" mode="copy">
  <xsl:copy>
    <xsl:apply-templates select="@*" mode="copy"/>
    <xsl:apply-templates mode="copy"/>
  </xsl:copy>
</xsl:template>

So far everythings works pretty fine.
But since I'm doing a lille bit more than just copying nodes 
I need to know the position if the parents node of the 
current node in its parent node.

Xpath's like this "parent::position()" dont'nt work. 

The only way I can think of a solution is to pass the 
position by a parameter.

<xsl:template match="@*|node()" mode="copy">
  <xsl:param name="parentsPos"/>
  <xsl:copy>
    <xsl:apply-templates select="@*" mode="copy"/>
    <xsl:apply-templates mode="copy">
      <xsl:with-param name="parentsPos" select="position()"/>
    </xsl:apply-template>
  </xsl:copy>
</xsl:template>

But this does'nt look that smart to me. The only parants 
position I ever going to know by this is the position of a 
direct parent of a node.

Is there a better way?

thanks & with best regards,
Jan

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--