[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Formatting issues
Hi ms,
I'm not sure I understand you. What is a level? Is that 1.1.1, 1.1.2 etc, as in legal documents? Or do you mean something like with chapters? Are the levels leveled in your document hierarchically, ie: <level1><level2><level3/></level2></level1> ? Do you really mean to match a part of the nodename? What actually is the problem with your current XSLT file? You talk of formatting, do you perhaps mean xsl-fo? If about XSLT, what version? Please answer the above in a subsequent post if I am on the wrong track here. The following self-contained XSLT 2.0 stylesheet takes your input, indents it depending on the real level (independent of your re-count request) and starts numbering anew when not at the right spot. Note that I employ the <xsl:next-match /> here to make life a little easier. If you cannot use XSLT 2.0, you'll have to add a few constructs to achieve the same goal, but the idea remains the same. The output of the below stylesheet is as follows (note the indentation and the numbering) (for input see variable $levels): At level 1, number: 1 At level 2, number: 1 At level 2, number: 2 At level 2, number: 3 At level 2, number: 4 At level 5, number: 1 At level 5, number: 2 At level 3, number: 1 At level 3, number: 2 At level 3, number: 3 The stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xs = "http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output indent="yes" /> <xsl:variable name="levels"> <level1> <level2 /> <level2 /> <level2 /> <level2 /> <level5 /> <!-- assuming this oddity is what you mean --> <level5 /> <!-- assuming this oddity is what you mean --> </level1> <level3 /> <!-- assuming this oddity is what you mean --> <level3 /> <level3 /> </xsl:variable> <xsl:template match="/"> <xsl:apply-templates select="$levels//*" /> </xsl:template> <!-- catch-all for the textual part --> <xsl:template match="*" priority="5"> <xsl:text>
</xsl:text> <xsl:value-of select=" for $i in 1 to xs:integer(substring(name(), 6, 1)) - 1 return ' '" /> <xsl:text>At level </xsl:text> <xsl:value-of select="concat(substring(name(), 6, 1), ', number: ')" /> <!-- apply again --> <xsl:next-match /> </xsl:template> <!-- wrong level, no correct parent --> <xsl:template match="*" priority="0"> <xsl:variable name="number"><xsl:number/></xsl:variable> <xsl:value-of select="$number" /> </xsl:template> <!-- correct level, with parent of one lower level --> <xsl:template match=" *[parent::*[ number(substring(name(), 6, 1)) = number(substring(current()/name(), 6, 1)) - 1] ]"> <xsl:variable name="number"><xsl:number/></xsl:variable> <xsl:value-of select="$number" /> </xsl:template> </xsl:stylesheet> HtH, Cheers, -- Abel http://www.nuntia.nl ms wrote: Hello:
|
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
|