Subject: Re: [xsl] Tricky XSLT 2.0 grouping problem From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 10 Oct 2008 11:28:19 -0400 |
I have a tricky grouping problem that I'm running into a wall with. I thought it might be a fun challenge to throw out there. I'm attempting to group a flat list of <section> elements into a hierarchy based on matching its number against different regular expressions.
The list is assumed to be in the correct order. I have it working (the code is
below) with one exception: roman numerals.
t:\ftemp>type sulak.xml <body> <section><pnum>(a)</pnum><p>First-level section</p></section> <section><pnum>(1)</pnum><p>Second-level section</p></section> <section><pnum>(A)</pnum><p>Third-level section</p></section> <section><pnum>(i)</pnum><p>Fourth-level section</p></section> <section><pnum>(ii)</pnum><p>Fourth-level section</p></section> <section><pnum>(B)</pnum><p>Third-level section</p></section> <section><pnum>(2)</pnum><p>Second-level section</p></section> <section><pnum>(A)</pnum><p>Third-level section</p></section> </body>
t:\ftemp>call xslt2 sulak.xml sulak.xsl sulak.out <?xml version="1.0" encoding="UTF-8"?> <section> <pnum>(a)</pnum> <p>First-level section</p> <section> <pnum>(1)</pnum> <p>Second-level section</p> <section> <pnum>(A)</pnum> <p>Third-level section</p> <section> <pnum>(i)</pnum> <p>Fourth-level section</p> </section> <section> <pnum>(ii)</pnum> <p>Fourth-level section</p> </section> </section> <section> <pnum>(B)</pnum> <p>Third-level section</p> </section> </section> <section> <pnum>(2)</pnum> <p>Second-level section</p> <section> <pnum>(A)</pnum> <p>Third-level section</p> </section> </section> </section><?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="body"> <xsl:call-template name="do-next-group"> <xsl:with-param name="level" select="1"/> <xsl:with-param name="population" select="section"/> </xsl:call-template> </xsl:template>
<xsl:template name="do-next-group"> <xsl:param name="level"/> <xsl:param name="population"/>
-- Upcoming XSLT/XSL-FO hands-on courses: Wellington, NZ 2009-01 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video sample lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg Video course overview: http://www.youtube.com/watch?v=VTiodiij6gE G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] select descendant problem, Michael Kay | Thread | RE: [xsl] Tricky XSLT 2.0 grouping , James Sulak |
RE: [xsl] Tricky XSLT 2.0 grouping , Michael Kay | Date | [xsl] Excluding a complete branch w, Fraser Goffin |
Month |