[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|