Re: [xsl] getting position of tag

Subject: Re: [xsl] getting position of tag
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 15 Sep 2004 11:55:16 -0400
Hi Dusan,

You don't really want "position()", which returns the position of the current node in the current node list. You haven't shown us what your template is matching here, so we don't know what either of those are, but it's not really a relevant question, since your XPath, which traverses from the root, suggests you want this number irrespective of the processing context.

Accordingly, you can do one of two things:

1. Count the columns preceding the column you want, and add 1:

xsl:value-of
 select="count(/columns/column[source='B']/preceding-sibling::column) + 1"

2. Change context to the column you want, and use the xsl:number instruction

<xsl:for-each select="/columns/column[source='B']">
  <xsl:number/>
</xsl:for-each>

(If you are in a template that has matched this node, the for-each instruction is unnecessary.)

Look up xsl:number to learn about its many powerful and useful features.

I hope that helps,
Wendell

At 09:55 AM 9/15/2004, you wrote:
Hi.

I have this problem:

XML:
<columns>
        <column>
                <source>A</source>
        </column>
        <column>
                <source>B</source>
        </column>
</xolumns>

I want to get position() of tag column, where source='B'.

I have tried
xsl:value-of select="/columns/column[source='B']/position()"
but it is bad.

Anyone help me?


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================


--+------------------------------------------------------------------ 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@xxxxxxxxxxxxxxxxxxxxxx> --+--

Current Thread