Subject: Re: [xsl] small grouping task From: Fred Christian <fredc@xxxxxxxxxx> Date: Thu, 26 Feb 2009 12:24:11 -0800 |
desired output. Only the <input>.....<br/> pairs are altered -------------------------------------------------------------------- <r> <p>text</p> <randomtag>surronding xhtml</randomtag> <p class="problem">some <b>xhtml</b> with<br/> no inputs<br/> <ul class="m"> <li class="m"> <span class="p">a</span><b>d </b></li> <li class="m"> <b>g </b><span class="p">b</span></li> </ul> <p>more</p> generic <b>xhtml</b> with<br/> no inputs<img src="l"/> </p> <b>a</b>surronding xhtml<b>b</b> </r> ------------------------------------------------------------------------------
current incorrect output, note: has missing items and misplaced items. ---------------------------------------------
<?xml version="1.0" encoding="UTF-8"?> <r> <p>text</p> <randomtag>surronding xhtml</randomtag> <ul class="m"> <li class="m"> <span class="p">a</span> <b>d </b> </li> <li class="m"> <b>g </b> <span class="p">b</span> <p>more</p> generic <b>xhtml</b> with no inputs<img src="l"/> </li> </ul> <b>a</b>surronding xhtml<b>b</b> </r>
current stylesheet (same as Ken's) ---------------------------------- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="p[@class = 'problem' and input]"> <!--start the list--> <ul class="m"> <!--find the members of the list, assuming multiple items per member--> <xsl:for-each-group select="node()" group-starting-with="input"> <xsl:if test="self::input"><!--found a group with an input--> <li class="m"> <!--copy everything except <br/> elements--> <xsl:apply-templates select="current-group()[position()>1] [not(self::br)]"/> </li> </xsl:if> </xsl:for-each-group> </ul> </xsl:template>
<xsl:template match="@*|node()"><!--identity for all other nodes--> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] small grouping task, G. Ken Holman | Thread | Re: [xsl] small grouping task, G. Ken Holman |
Re: [xsl] small grouping task, G. Ken Holman | Date | Re: [xsl] small grouping task, G. Ken Holman |
Month |