Subject: Re: [xsl] Merging like Siblings within a variable as="element()*" From: Alex Muir <alex.g.muir@xxxxxxxxx> Date: Fri, 20 Aug 2010 15:31:32 +0000 |
Martin, I'm using XSLT 2.0 but selecting the value out of the group rather then copying the elements in the group had not occurred to me. <xsl:value-of select="current-group()" separator=""/> Don't be astonished, I'm still within my first year of coding XSLT 2.0 and capable of pouring orange juice, rather than milk, in my cereal unaware ;) Thanks Much Alex On Fri, Aug 20, 2010 at 3:07 PM, Martin Honnen <Martin.Honnen@xxxxxx> wrote: > Alex Muir wrote: >> >> Hi, >> >> I've been using the following code that works based on templates to >> merge <chunk> siblings beside one another such that the following >> >> <chunk>1</chunk> >> <chunk>2</chunk> >> <notChunk>3</notChunk> >> <chunk>4</chunk> >> <chunk>5</chunk> >> >> would be merged to >> >> <chunk>12</chunk> >> <notChunk>3</notChunk> >> <chunk>45</chunk> >> >> Here is the code: >> <xsl:template match="chunk" priority="1"> >> <xsl:copy> >> <xsl:copy-of select="@*"/> >> <xsl:copy-of select="text()"/> >> <xsl:apply-templates >> select="following-sibling::*[1][self::chunk]" >> mode="more"/> >> </xsl:copy> >> </xsl:template> >> >> <xsl:template match="chunk[preceding-sibling::*[1][self::chunk]]" >> priority="2"/> >> >> <xsl:template match="chunk" mode="more"> >> <xsl:copy-of select="text()"/> >> <xsl:apply-templates >> select="following-sibling::*[1][self::chunk]" >> mode="more"/> >> </xsl:template> >> >> >> This works great if I'm applying the templates to an xml file however >> I'm interested to have the chunks within a <xsl:variable >> name="content" as="element()*> and then merge them and output them and >> I'm not sure how to go about merging the like siblings within a >> variable. >> >> Any suggestions are highly appreciated? > > The as="element()*" suggests you are using XSLT 2.0, then I am astonished > you are not using xsl:for-each-group group-adjacent from the beginning. > Are you using XSLT 2.0? Can't you use > <xsl:for-each-group select="$your-variable" > group-adjacent="boolean(self::chunk)"> > <xsl:choose> > <xsl:when test="current-grouping-key()"> > <chunk><xsl:value-of select="current-group()" separator=""/></chunk> > </xsl:choose> > <xsl:otherwise> > <xsl:copy-of select="current-group()"/> > </xsl:otherwise> > </xsl:choose> > </xsl:for-each-group> > > -- > > Martin Honnen > http://msmvps.com/blogs/martin_honnen/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Merging like Siblings wit, Martin Honnen | Thread | [xsl] Question on duplicate node el, Hermann Stamm-Wilbra |
Re: [xsl] check for whitespace valu, Wendell Piez | Date | Re: [xsl] check for whitespace valu, Dimitre Novatchev |
Month |