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

Re: displaying position of nodes

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

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
elements.

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"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

The output is:

<body>
1root:
  2desktop:
    3window: main
    4window: sub
    5pane:
      6button: one
      7button: two


</body>

I hope this is more or less what you wanted.


Hope this helped.


=====
Cheers,

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

"Mac Martine" <email@xxxxxxxxxxxxxxxx> wrote in message
news:000b01c2d923$f4b1a200$723b2099@xxxxxxxx
> 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
>
> XSL
> ===========================
> <?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>
>
> XML
> ============================
> <root>
> <desktop>
> <window>main</window>
> <window>sub</window>
> <pane>
> <button>one</button>
> <button>two</button>
> </pane>
> </desktop>
> </root>
>
> RESULT
> 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

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.