xsl-list
[Top] [All Lists]

[xsl] Merging like Siblings within a variable as="element()*"

2010-08-20 09:57:33
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?


Thanks Much
Alex

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>