[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Problem using preceding-sibling
Hi, I try to get the immediate sibling by checking the position, however I get always the first node. <xsl:variable name="cpo" select="position()"/> <xsl:element name="Preceding_GID"> <xsl:value-of select="generate-id(preceding-sibling::node()[position()= $cpo - 1])"/> </xsl:element> Thanks for any help, Faroukh ---XML <Project> <Level1> <Element1/> <Level2> <ID>1</ID> </Level2> <Level2> <ID>2</ID> </Level2> <Level2> <ID>3</ID> </Level2> <Level2> <ID>4</ID> </Level2> </Level1> </Project> --- XSLT <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <xsl:apply-templates select="Project"/> </xsl:template> <xsl:template match="Project"> <Project> <xsl:for-each select="Level1"> <xsl:call-template name="Level1"/> </xsl:for-each> </Project> </xsl:template> <xsl:template name="Level1"> <Level1> <xsl:for-each select="Level2"> <xsl:call-template name="Level2"/> </xsl:for-each> </Level1> </xsl:template> <xsl:template name="Level2"> <xsl:variable name="GID" select="generate-id()"/> <xsl:variable name="cpo" select="position()"/> <Level2> <xsl:if test="position()>1"> <xsl:element name="Preceding_GID"> <xsl:value-of select="generate-id(preceding-sibling::node()[position()= $cpo - 1])"/> </xsl:element> </xsl:if> <xsl:element name="ID"> <xsl:value-of select="ID"/> </xsl:element> <xsl:element name="GID"> <xsl:value-of select="$GID"/> </xsl:element> </Level2> </xsl:template> </xsl:stylesheet> And the wrong result is <?xml version="1.0" encoding="UTF-8"?> <Project> <Level1> <Level2> <ID>1</ID> <GID>IDAAK42B</GID> </Level2> <Level2> <Preceding_GID>IDAAK42B</Preceding_GID> <ID>2</ID> <GID>IDACK42B</GID> </Level2> <Level2> <Preceding_GID>IDAAK42B</Preceding_GID> <! it should be IDACK42B <ID>3</ID> <GID>IDAEK42B</GID> </Level2> <Level2> <Preceding_GID>IDAAK42B</Preceding_GID> <! it should be IDAEK42B <ID>4</ID> <GID>IDAGK42B</GID> </Level2> </Level1> </Project> 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
|