[xsl] Re: displaying position of nodes

Subject: [xsl] Re: displaying position of nodes
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Fri, 21 Feb 2003 07:00:55 +0100
First of all, you haven't explained what do you mean by "position of the

Then, you are speaking about "node" but your template matches elements.

I gather that you'd like to produce the relative number of every element in
document order. Is this so?

Then, what do you mean by "the value of the node"? The string value of an
element is the concatenated values of all of its text-node descendents --
this will not produce a nice output and I doubt this is what you really
wanted. I will output the element name instead.

Then, most important, your template, which matches elements, will be
instantiated only against the top element ("root").

The most important correction to your template is to ensure that the
transformation (the template matching) process continues against other

Therefore, an xsl:apply-templates need be added at the end of the code of
your template. This will apply templates to all children of the current node
and will trigger the default template for text nodes. This is how "the
value" of the nodes will also be produced.

The modified code is:

<xsl:stylesheet version="1.0"

  <xsl:output omit-xml-declaration="yes"/>
  <xsl:template match="/">
      <xsl:apply-templates  />
  <xsl:template match="*">
    <xsl:number count="*" level="any"/>
    <xsl:value-of select="concat(name(), ': ')"/>

The output is:

    3window: main
    4window: sub
      6button: one
      7button: two


I hope this is more or less what you wanted.

Hope this helped.


Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Mac Martine" <email@xxxxxxxxxxxxxxxx> wrote in message
> Argh.
> I'm trying to loop through all the nodes and display the position of the
> node next to the value of the node. The values display, but only one of
> the positions displays. Why is that??? The same happens if I try to
> display local-name().
> Thanks-
>  Mac
> ===========================
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> <xsl:template match="/">
> <body>
> <xsl:apply-templates  />
> </body>
> </xsl:template>
> <xsl:template match="*">
> <xsl:value-of select="."/>
> <xsl:value-of select="position()"/>
> </xsl:template>
> </xsl:stylesheet>
> ============================
> <root>
> <desktop>
> <window>main</window>
> <window>sub</window>
> <pane>
> <button>one</button>
> <button>two</button>
> </pane>
> </desktop>
> </root>
> Displays:
> main sub one two 1
> xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

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

Current Thread