Subject: [xsl] different results with xalan and msxsl/saxon From: "Frank" <fweenink@xxxxxxxxx> Date: Mon, 18 Feb 2002 10:46:29 +0100 |
With following xml file I wanted to create a stylesheet to get a nested structure. So with heading 2 as a child of heading 1, etc. <file> <p stylename="heading 1">1. title</p> <p stylename="Body Text">body text</p> <p stylename="Body Text">body text</p> <p stylename="heading 2">1.1 title</p> <p stylename="Body Text">body text</p> <p stylename="Body Text">body text</p> <p stylename="List Bullet">list item</p> <p stylename="List Bullet">list item</p> <p stylename="heading 3">1.1.1 title</p> <p stylename="Body Text">body text</p> <table> <row> <cell> <p>text</p> </cell> </row> </table> <p stylename="Body Text">body text</p> <p stylename="heading 2">1.2 title</p> <p stylename="Body Text">body text</p> <p stylename="Body Text">body text</p> <p stylename="heading 1">2. title</p> <p stylename="Body Text">body text</p> <p stylename="Body Text">body text</p> <p stylename="List Bullet">list item</p> <p stylename="List Bullet">list item</p> <p stylename="heading 2">2.1 title</p> <p stylename="Body Text">body text</p> </file> So I made this stylesheet: <!-- key for selecting the p and table elements between the headings --> <xsl:key name="body-text" match="file/node()[not(starts-with(@stylename, 'heading')) or not(@stylename)]" use="preceding-sibling::p[starts-with(@stylename, 'heading')][1]"/> <!-- selecting the headings with one level higher than the preceding heading --> <xsl:key name="headings" match="file/p[starts-with(@stylename, 'heading')]" use="preceding-sibling::p[starts-with(@stylename, 'heading')] [substring(@stylename, 9 , 1)=substring(current()/@stylename, 9, 1)-1][1]"/> <xsl:template match="file"> <xsl:copy> <xsl:apply-templates select="p[starts-with(@stylename, 'heading 1')]"/> </xsl:copy> </xsl:template> <!-- match all headings for recursiveness(is that good English?) --> <xsl:template match="p[starts-with(@stylename, 'heading')]"> <xsl:variable name="level" select="substring(@stylename, 9, 1)"/> <section> <titel><xsl:apply-templates select="@stylename"/><xsl:value-of select="."/></titel> <body> <xsl:for-each select="key('body-text', current())"> <xsl:apply-templates select="current()"/> </xsl:for-each> </body> <xsl:for-each select="key('headings', current())"> <xsl:apply-templates select="current()"/> </xsl:for-each> </section> </xsl:template> <!-- copy --> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> With xalan 2.2 D14 I got a good result, but with msxsl and saxon the stylesheet only selected heading 1. xalan: <section> <titel stylename="heading 1">1. title</titel> <body> <p stylename="Body Text">body text</p> <p stylename="Body Text">body text</p> </body> <section> <titel stylename="heading 2">1.1 title</titel> <body> <p stylename="Body Text">body text</p> <p stylename="Body Text">body text</p> <p stylename="List Bullet">list item</p> <p stylename="List Bullet">list item</p> </body> <section> <titel stylename="heading 3">1.1.1 title</titel> ..................... etc. msxsl, saxon: <file> <section> <titel stylename="heading 1">1. title</titel> <body> <p stylename="Body Text">body text</p> <p stylename="Body Text">body text</p> </body> </section> <section> <titel stylename="heading 1">2. title</titel> <body> <p stylename="Body Text">body text</p> <p stylename="Body Text">body text</p> <p stylename="List Bullet">list item</p> <p stylename="List Bullet">list item</p> </body> </section> </file> Is xalan going rong here? And is there a better way to handle this? XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Evaluation of a string co, Michael Kay | Thread | Re: [xsl] different results with xa, Jeni Tennison |
Re[2]: [xsl] simple method for list, klaus e. werner | Date | RE: [xsl] Newbie: SECOND POST - Hel, Bryan Rasmussen |
Month |