[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Problem with grouping sibling tags
At 2008-12-23 12:12 +0100, Casper Voortman wrote:
The second link post seems more in the direction of what i'm looking for, but unfortunately i'm not completely grasping the process. Will study it harder, but this is 'higher' xslt writing for me. ... Op 23 dec 2008, om 11:45 heeft Michael Kay het volgende geschreven:And in particular Ken Holman's post at http://markmail.org/message/teo6uftbxjvsa56c (dated 22 Oct 1999) which must be the earliest exposition of the technique often called "sibling recursion". Thanks, Michael, for citing that. Casper, the sentence for: not(preceding-sibling::*[1][self::Paragraph][@Pstyle='PlattetekstBullet']) is "it is not true that the immediately preceding sibling is a paragraph with the particular style". The sentence for: following-sibling::*[1][self::Paragraph][@Pstyle='PlattetekstBullet'] is "the imeediately following sibling if it is a paragraph with the particular style". And both are brought together in the running example below that is almost identical to the one posted nine years ago. I wrote the below before looking back and I see that nothing really has changed. I hope this helps. Happy holidays to everyone on the list! . . . . . . . . . Ken
T:\ftemp>call xslt casper.xml casper.xsl casper.out T:\ftemp>type casper.out <?xml version="1.0" encoding="utf-8"?> <section role="BroodTekst"> <title role="tussenkop">textcontent</title> <para role="plattetekstInitiaal"> textcontent </para> <itemizedlist> <listitem> <para role="plattetekstBullet"> bullet1 </para> </listitem> <listitem> <para role="plattetekstBullet"> bullet2 </para> </listitem> </itemizedlist> <para role="plattetekst"> textcontent </para> <para role="plattetekst"> textcontent </para> <itemizedlist> <listitem> <para role="plattetekstBullet"> bullet3 </para> </listitem> </itemizedlist> </section> T:\ftemp>type casper.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output indent="yes"/> <xsl:template match="Frame"> <section role="{@Label}"><xsl:apply-templates select="*"/></section> </xsl:template> <xsl:template match="Paragraph[@Pstyle='Tussenkop']"> <title role="tussenkop"><xsl:apply-templates select="Text"/></title> </xsl:template> <xsl:template match="Paragraph[@Pstyle='PlattetekstInitiaal']"> <para role="plattetekstInitiaal"><xsl:apply-templates/></para> </xsl:template> <xsl:template match="Paragraph[@Pstyle='Plattetekst']"> <para role="plattetekst"><xsl:apply-templates/></para> </xsl:template> <xsl:template match="Paragraph[@Pstyle='PlattetekstBullet']"> <!--only do something if this is the first of consecutive siblings--> <xsl:if test="not(preceding-sibling::*[1][self::Paragraph] [@Pstyle='PlattetekstBullet'])"> <itemizedlist> <xsl:apply-templates mode="next-list-item" select="."/> </itemizedlist> </xsl:if> </xsl:template> <xsl:template mode="next-list-item" match="Paragraph[@Pstyle='PlattetekstBullet']"> <listitem> <para role="plattetekstBullet"><xsl:apply-templates/></para> </listitem> <!--keep building the list as long as there are consecutive siblings--> <xsl:apply-templates mode="next-list-item" select="following-sibling::*[1][self::Paragraph] [@Pstyle='PlattetekstBullet']"/> </xsl:template> </xsl:stylesheet> T:\ftemp>rem Done! -- 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 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
|
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
|