Hi all,
Sometimes I am baffled about how to approach something. Sometimes I'm baffled
by why something doesn't work.
Using XSLT 2.0, I have the input XML:
<contrib-group>
<contrib><name>Bob</name><xref rid="aff1"/></contrib>
<contrib><name>Judy</name><xref rid="aff2"/></contrib>
</contrib-group>
<aff id="1"><label>1</label>Kingdom of Curds</aff>
<aff id="2"><label>2</label>Land of Whey</aff>
<contrib-group>
<contrib><name>Jimmy</name><xref rid="aff3"/></contrib>
</contrib-group>
<aff id="3"><label>2</label>Duchy of Lambic-Soaked Cheese Rind</aff>
I'm trying to get:
<contrib-group>
<contrib><name>Bob</name><xref rid="aff1"/></contrib>
<contrib><name>Judy</name><xref rid="aff2"/></contrib>
<aff id="1">Kingdom of Curds</aff>
<aff id="2">Land of Whey</aff>
</contrib-group>
<contrib-group>
<contrib><name>Jimmy</name><xref rid="aff3"/></contrib>
<aff id="3">Duchy of Lambic-Soaked Cheese Rind</aff>
</contrib-group>
That is, move the following <aff> elements into the <contrib-group> and remove
the <label>. But what I get is
<contrib-group>
<contrib><name>Bob</name><xref rid="aff1"/></contrib>
<contrib><name>Judy</name><xref rid="aff2"/></contrib>
<aff id="1">Kingdom of Curds</aff>
<aff id="2">Land of Whey</aff>
<aff id="3">Duchy of Lambic-Soaked Cheese Rind</aff>
</contrib-group>
<contrib-group>
<contrib><name>Jimmy</name><xref rid="aff3"/></contrib>
<aff id="3">Duchy of Lambic-Soaked Cheese Rind</aff>
</contrib-group>
That is, the third <aff> is getting drawn into the first <contrib-group>. Even
I could figure out that starting from the context node <contrib-group>, the
following-sibling axis would draw in all three <aff> elements. But that's what
grouping is for, so...
<xsl:template match="contrib-group">
<xsl:copy>
<xsl:apply-templates/>
<xsl:for-each-group select="following-sibling::aff"
group-starting-with="contrib-group">
<xsl:for-each select="current-group()">
<xsl:copy >
<xsl:attribute name="id"><xsl:value-of
select="./@id"/></xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:for-each>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
<xsl:template match="aff"/>
<xsl:template match="aff/label"/>
I've tried different grouping variations, like using @group-adjacent, but I get
the same result. I have a feeling that the problem is in the <xsl:for-each
select="current-group()">, but this template looks a lot like the sample code
on various tutorials.
???
(I've gotten much help from this list, and I really need to take the time to
get further in Ken's Udemy course! The next time I see any of you, I'll owe you
a beer, a homebrew if I'm not flying. I've got a robust porter wet-hopped from
the vines in my back yard and a Flemish sour with black currants.)
Thanks,
Charles
Charles O'Connor l Business Systems Analyst
Pronouns: He/Him
Aries Systems Corporation l www.ariessys.com
50 High Street, Suite 21 l North Andover, MA l 01845 l USA
Main: +1 (978) 975-7570
Cell: +1 (802) 585-5655
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--