[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] position() return's only even numbers for nested eleme
Hello, please take a look at this xsl fragment, maybe you find a simple explanation to strange behaviour of position() function for nested elements. Consider this input xml: <uml> <package id="1"/> <package id="2"/> <package id="3"> <package id="31"/> <package id="32"/> </package> <package id="4"> <package id="41"> <package id="411"/> <package id="412"/> <package id="413"/> </package> </package> <package id="5"/> </uml> Now I want to print position of every single 'package' element: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="uml"> <result> <xsl:apply-templates select="package"/> </result> </xsl:template> <xsl:template match="package"> <xsl:copy> <xsl:copy-of select="@id"/> <xsl:attribute name="position"><xsl:value-of select="position()"/></xsl:attribute> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet> And the result under Saxon and Xalan is: <result> <package id="1" position="1"/> <package id="2" position="2"/> <package id="3" position="3"> <package id="31" position="2"/> <package id="32" position="4"/> </package> <package id="4" position="4"> <package id="41" position="2"> <package id="411" position="2"/> <package id="412" position="4"/> <package id="413" position="6"/> </package> </package> <package id="5" position="5"/> </result> Why all nested 'package' element have even positions (2, 4, 6, ...) but top-level 'package' elements positions behaves right (1, 2, 3,...) ??? When I replace <xsl:apply-templates/> with <xsl:apply-templates select="packages"/>, then it works right also for nested 'packages' elements. I''ll be thankful for every explanation. Michal XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|