xsl-list
[Top] [All Lists]

[xsl] using for-each-group to wrap an element

2011-08-23 04:08:53
Good morning,

I'm still working with for-each-group in order to wrap an element around adjacent siblings. I decided to use a 2nd transformation to take care of the grouping. I'm getting closer, but I don't know what I've done wrong here.

Again, thank you for your help.

Input:
<root>
<ChapterTitle>...</ChapterTitle>
<H1>...</H1>
<Para>...</Para>
<Para>...</Para>
<AnchoredGraphic><img src="..."/></AnchoredGraphic>
<H1>...</H1>
<Para>...</Para>
<H2>...</H2>
<Para>...</Para>
<FeatureType>...</FeatureType>
<FeaturePara>...</FeaturePara>
<ListNumbered>...</ListNumbered>
<ListNumbered>...</ListNumbered>
<ListPara>...</ListPara>
<ListNumbered>...</ListNumbered>
</root>

Desired Output:
<root>
<ChapterTitle>...</ChapterTitle>
<H1>...</H1>
<Para>...</Para>
<Para>...</Para>
<AnchoredGraphic><img src="..."/></AnchoredGraphic>
<H1>...</H1>
<Para>...</Para>
<H2>...</H2>
<Para>...</Para>
<AnchoredFeature>
<FeatureType>...</FeatureType>
<FeaturePara>...</FeaturePara>
</AnchoredFeature
<ListNumbered>...</ListNumbered>
<ListNumbered>...</ListNumbered>
<ListPara>...</ListPara>
<ListNumbered>...</ListNumbered>
</root>

Current output:
<root>
<ChapterTitle>...</ChapterTitle>
<H1>...</H1>
<Para>...</Para>
<Para>...</Para>
<AnchoredGraphic><img src=".."/></AnchoredGraphic>
<H1>...</H1>
<Para>...</Para>
<H2>...</H2>
<Para>...</Para>
<AnchoredFeature><FeatureType>...</FeatureType></AnchoredFeature>
<AnchoredFeature><FeaturePara>...</FeaturePara></AnchoredFeature>
<ListNumbered>...</ListNumbered>
<ListNumbered>...</ListNumbered>
<ListPara>...</ListPara>
<ListNumbered>...</ListNumbered>
</root>

XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">
<xsl:template match="root">
 <xsl:element name="root">
<xsl:for-each-group select="child::node()" group-adjacent="starts- with(name(),'Feature')">
    <xsl:choose>
  <xsl:when test="current-grouping-key()">
   <xsl:element name="AnchoredFeature">
    <xsl:copy-of select="current-group()"/>
   </xsl:element>
  </xsl:when>
  <xsl:otherwise>
   <xsl:copy-of select="current-group()"/>
  </xsl:otherwise>
    </xsl:choose>
  </xsl:for-each-group>
 </xsl:element>
</xsl:template>
</xsl:stylesheet>


--~------------------------------------------------------------------
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>