[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

using for-each-group to wrap an element

Subject: using for-each-group to wrap an element
From: Jeff Wilson <jeffrey@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 23 Aug 2011 02:08:38 -0700
 using for-each-group to wrap an element
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>


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.