Subject: Re: [xsl] Using operators >> and << From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Mon, 12 Jan 2009 20:16:26 -0500 |
I need to take the following markup:
...
And turn it into:
It is easy enough to identify and format the <ulist/> based on the occurrence of the first <bullet/> but then isolating just the remaining contiguous bullets eludes me.
I have the feeling that I can use the << or >> operators to select all of the bullets until the node name changes in the document order.
However, I can only find very sketchy documentation regarding these constructs and when I try to use them I get syntax errors.
Any suggestions or pointers on where I could look for working examples (not shorthand) of how these constructs can be used or suggestions on a different approach would be very much appreciated.
t:\ftemp>type steve.xml <steve> <para>a para of data</para> <bullet>first bullet data</bullet> <bullet>second bullet data</bullet> <bullet>third bullet data</bullet> <para>more para data</para> <bullet>another bullet list</bullet> </steve>
t:\ftemp>call xslt2 steve.xml steve.xsl <?xml version="1.0" encoding="UTF-8"?> <para>a para of data</para> <ulist> <listitem> <para>first bullet data</para> </listitem> <listitem> <para>second bullet data</para> </listitem> <listitem> <para>third bullet data</para> </listitem> </ulist> <para>more para data</para> <ulist> <listitem> <para>another bullet list</para> </listitem> </ulist> t:\ftemp>type steve.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="steve"> <!--find all adjacent groups that are or not made up of bullets--> <xsl:for-each-group select="*" group-adjacent="boolean(self::bullet)"> <xsl:choose> <xsl:when test="self::bullet"> <!--here is an adjacent group that is made up of bullets--> <ulist> <xsl:for-each select="current-group()"> <listitem><para><xsl:apply-templates/></para></listitem> </xsl:for-each> </ulist> </xsl:when> <xsl:otherwise> <!--here is an adjacent group that is not made up of bullets--> <xsl:apply-templates select="current-group()"/> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:template>
<xsl:template match="@*|node()"><!--identity for all other nodes--> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
</xsl:stylesheet> t:\ftemp>
-- Upcoming XSLT/XSL-FO, UBL and code list hands-on training classes: : Sydney, AU 2009-01/02; Brussels, BE 2009-03; Prague, CZ 2009-03 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 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 -> |
---|---|---|
[xsl] Using operators >> and <<, Ylvisaker, Steve | Thread | [xsl] Using XSLT as a namespace fil, Nathan Potter |
[xsl] Using XSLT as a namespace fil, Nathan Potter | Date | [xsl] To control node duplication, nick public |
Month |