[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] grouping, xslt 2.0
I'm trying to get an example working from MKay book, using starting-with. The idea is to nest a flat structure properly, based on heading level. The p elements are not being processed as I'd want (duplicated etc) and the nesting isn't correct. Any suggestions what's wrong please? JJ xml <grpStart> <h1>Usual html example, flat, with properly stacked levels</h1> <p>Each block must have one child</p> <h1>The instance must start with <b>h1</b></h1> <p>I.e. the headings can follow with no more than one difference</p> <p>1 2 3 3 4 5 4 3 etc</p> <h2>Invalid sequences</h2> <h2>Which might be, in fact</h2> <p>are 1 followed by 3</p> <p>or 4 2</p> <h3>That's the way it goes</h3> <p>Each block must have at least one child</p> <h3>The hard part is persuading authors to follow style guidelines</h3> <p>All blocks must have children</p> </grpStart> xsl xmlns:xs="http://www.w3.org/2001/XMLSchema-datatypes" exclude-result-prefixes="xs" version="2.0"> <xsl:output method="xml" indent="yes" encoding="utf-8"/> <xsl:template match="/"> <op> <xsl:apply-templates select="//grpStart"/> </op> </xsl:template> <xsl:template match="grpStart"> <xsl:for-each-group select="*" group-starting-with="h1"> <xsl:apply-templates select="."/> </xsl:for-each-group> </xsl:template> <xsl:template match="*[starts-with(name(),'h')]"> <xsl:message> Match on <xsl:value-of select="name()"/> Population is <xsl:value-of select="count(current-group())"/> </xsl:message> <section level="{substring-after(name(),'h')}"> <head><xsl:apply-templates/></head> <xsl:for-each-group select="current-group() except ." group-starting-with="*[name() = translate(name(current()),'1234','2345')]"> <xsl:apply-templates select="current-group()"/> </xsl:for-each-group> </section> </xsl:template> <xsl:template match="p"> <para><xsl:apply-templates/></para> </xsl:template> <xsl:template match="b"> <emph><xsl:apply-templates/></emph> </xsl:template> </xsl:stylesheet> actual output <op> <section level="1"> <head>Usual html example, flat, with properly stacked levels</head> <para>Each block must have one child</para> </section> <section level="1"> <head>The instance must start with <emph>h1</emph> </head> <para>I.e. the headings can follow with no more than one difference</para> <para>1 2 3 3 4 5 4 3 etc</para> <section level="2"> <head>Invalid sequences</head> <para>1 2 3 3 4 5 4 3 etc</para> <section level="2"> <head>Which might be, in fact</head> <para>1 2 3 3 4 5 4 3 etc</para> </section> </section> <section level="2"> <head>Which might be, in fact</head> <para>1 2 3 3 4 5 4 3 etc</para> <section level="2"> <head>Invalid sequences</head> <para>1 2 3 3 4 5 4 3 etc</para> </section> </section> <para>are 1 followed by 3</para> <para>or 4 2</para> <section level="3"> <head>That's the way it goes</head> <para>or 4 2</para> </section> <para>Each block must have at least one child</para> <section level="3"> <head>The hard part is persuading authors to follow style guidelines</head> <para>Each block must have at least one child</para> </section> <para>All blocks must have children</para> </section> </op> ___________________________________________________________ New Yahoo! Mail is the ultimate force in competitive emailing. Find out more at the Yahoo! Mail Championships. Plus: play games and win prizes. http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk
|
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
|