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 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>
</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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] displaying position of nodes, Mac Martine | Thread | Re: [xsl] Re: displaying position o, S Woodside |
[xsl] Running both Saxon and Xalan?, Dimitre Novatchev | Date | [xsl] Re: displaying position of no, Dimitre Novatchev |
Month |