xsl-list
[Top] [All Lists]

RE: xslt 2.0: grouping flat element structures to make lists

2005-05-26 03:29:11
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[(_at_)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[(_at_)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[(_at_)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[(_at_)class='Listitem']"/>

so all list items go in the main run

and have a template

<xsl:template match="par[(_at_)class='Listbegin']">
that starts a <list> and grabs all the following items, something like


<xsl:template match="par[(_at_)class='Listbegin']">
<list>
<xsl:apply-templates mode="l" select="following-sibling::*[1]"/>
</list>
</xsl:template>

<xsl:template mode="l" match="par[(_at_)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




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--