Subject: RE: [xsl] xslt 2.0: grouping flat element structures to make lists From: "Derek Revill" <derek@xxxxxxxxxxxxxxxxxx> Date: Thu, 26 May 2005 11:29:11 +0100 |
Thanks to David. Plan b) was the way to go for me i.e. using a clever switch to a special "list-processing mode" and gathering the required item nodes after the list-begin "trigger node". Creating a "dead-end" template in the list-processing mode for any following-sibling NON list-item nodes ensured the list only contained the required items, and that redundant node processing in the list-processing mode was brought to an end. I had just assumed that I should be using the new XSLT v2 features to solve my problem. Basic XSLT v1 approach was better in the end. Thanks again. Derek For reference final solution was (NB: my default mode here is called 'phase 2'): <xsl:template match="par[@class='ListBegin']" mode="phase2"> <list-match-ph2> <!-- Switch to a list-processing mode to get following items--> <xsl:apply-templates select="following-sibling::*[1]" mode="list-processing"/> </list-match-ph2> </xsl:template> <xsl:template match="par[@class='Listitem']" mode="list-processing"> <item-lp><xsl:apply-templates mode="phase2"/></item-lp> <!-- Try processing the following-sibling, it may be another list item --> <xsl:apply-templates select="following-sibling::*[1]" mode="list-processing"/> </xsl:template> <!-- Soak-up nodes / Create dead-end processing --> <xsl:template match="par[@class='Listitem']" mode="phase2"/> <xsl:template match="*" mode="list-processing"/> > > plan b) Don't use for-each group at all. > just have your normal transformation templates, then add a template > > <xsl:template match="par[@class='Listitem']"/> > > so all list items go in the main run > > and have a template > > <xsl:template match="par[@class='Listbegin']"> > that starts a <list> and grabs all the following items, something like > > > <xsl:template match="par[@class='Listbegin']"> > <list> > <xsl:apply-templates mode="l" select="following-sibling::*[1]"/> > </list> > </xsl:template> > > <xsl:template mode="l" match="par[@class='Listitem']"> > <item><xsl:apply-templates/></xsl:item> > <xsl:apply-templates mode="l" select="following-sibling::*[1]"/> > </xsl:template> > > > <xsl:template mode="l" match="*"/> > > > Actually I was going to use plan (b) in my first reply, but then I > noticed that you said you wanted to use XSLT 2 grouping constructs > and plan b isn't very good as a teach-yourself-xslt2 example, as it's > xslt1:-) > > > David
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] xslt 2.0: grouping flat e, David Carlisle | Thread | [xsl] getting sibling text, jpk |
RE: [xsl] How to trim leading and t, Michael Kay | Date | RE: [xsl] How to trim leading and t, Mukul Gandhi |
Month |