Olaf P�schel <[EMAIL PROTECTED]> writes:

> I'm seeking for someone who can explain what I am doing wron with
> the position() function. Asume following xml file:
>
> <?xml version='1.0'?>
> <top>
>   <sub>one</sub>
>   <sub>two</sub>
>   <sub>three</sub>
> </top>
>
> Then here is a XSL(T) stylesheet
>
> ?xml version="1.0" encoding="ISO-8859-1"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
>   <xsl:template match="top">
>     A List
>
>     <xsl:apply-templates/>
>   </xsl:template>
>
>   <xsl:template match="sub">
>     <xsl:value-of select="position()"/>
>     <xsl:text>) </xsl:text>
>     <xsl:value-of select="."/>
>   </xsl:template>
> </xsl:stylesheet>
>
> which gives the following output:
>
> <?xml version="1.0"?>
>
>     A List
>
>     
>   2) one
>   4) two
>   6) three
>
> This is just fine. Besides is there a simple way to make it output
> 1, 2 and 3?

The XSL position() function is also counting the whitespace nodes that
separate your <sub> elements. This is normal. You can tell the XSLT
processor to strip the whitespace within the <top> element by adding:

   <xsl:strip-space elements="top"/>

to your stylesheet, which should then give you the count of <sub>
elements only.

You might find this article helpful:

   http://www.xml.com/pub/a/2001/11/07/whitespace.html

Cheers,

Chad

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to