[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Nodes get new IDs in function?
As Ken Holman (and I, http://markmail.org/message/4kneb3v2y6d4jlur)
recently suggested: this problem is probably better solved by a grouping
approach.
XSLT: ======8<---------------------------------- <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:my="URN:my" version="2.0" exclude-result-prefixes="my xs" > <xsl:output method="xml" indent="yes" /> <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="body"> <xsl:copy> <xsl:sequence select="my:hierarchize(*,1)" /> </xsl:copy> </xsl:template> <xsl:function name="my:hierarchize" as="element(*)*"> <xsl:param name="nodes" as="element(*)*" /> <xsl:param name="outline-level" as="xs:double?" /> <xsl:choose> <xsl:when test="empty($outline-level)"> <!-- no output for non-headings, as we are creating the ToC: --> <!-- <xsl:sequence select="$nodes" /> --> </xsl:when> <xsl:otherwise> <ul> <xsl:for-each-group select="$nodes" group-starting-with="*[matches(name(), '^h\d$')] [my:hlevel(.) = $outline-level]"> <xsl:choose> <xsl:when test="my:hlevel(current-group()[1]) = $outline-level"> <li class="level{$outline-level}"> <p> <xsl:copy-of select="current-group()[1]/node()" /> </p> <xsl:variable name="new-nodes" select="current-group()[position() gt 1]" as="node()*" /> <xsl:sequence select="my:hierarchize( $new-nodes, min( for $n in $new-nodes[ matches(name(), '^h\d$') ] return my:hlevel($n) ) )" /> </li> </xsl:when> <xsl:otherwise> <xsl:sequence select="my:hierarchize( current-group(), min( for $n in current-group()[ matches(name(), '^h\d$') ] return my:hlevel($n) ) )" /> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </ul> </xsl:otherwise> </xsl:choose> </xsl:function> <xsl:function name="my:hlevel" as="xs:double"> <xsl:param name="elt" as="element(*)" /> <xsl:value-of select="number(replace(name($elt), '^h(\d)$', '$1'))" /> </xsl:function> </xsl:stylesheet> ======8<----------------------------------
De rien. Gerrit On 09.04.2010 02:15, Martynas Jusevicius wrote: Hey list,
Registergericht / Commercial Register: Amtsgericht Leipzig Registernummer / Registration Number: HRB 24930 Geschdftsf|hrer: Gerrit Imsieke, Svea Jelonek, Thomas Schmidt, Dr. Reinhard Vvckler
|
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
|