Thanks Mukul!
I will give that a try.
Best,
Charles
From: Mukul Gandhi mukulg(_at_)softwarebytes(_dot_)org
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Tuesday, June 15, 2021 12:33 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] We need to kick someone out of the group
*** External email: use caution ***
On Fri, Jun 11, 2021 at 5:56 PM Charles O'Connor
coconnor(_at_)ariessys(_dot_)com<mailto:coconnor(_at_)ariessys(_dot_)com>
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com<mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>>
wrote:
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>
Here's what I tried and which works.
My XML input document,
<temp>
<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>
</temp>
My XSLT 2.0 stylesheet,
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="contrib-group">
<xsl:variable name="c_grp" select="."/>
<xsl:copy>
<xsl:apply-templates/>
<xsl:variable name="affList">
<xsl:apply-templates select="$c_grp/following-sibling::*[1]"
mode="m1"/>
</xsl:variable>
<xsl:for-each select="$affList/*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="node()[not(self::label)]"/>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template match="aff"/>
<xsl:template match="*" mode="m1">
<xsl:if test="self::aff">
<xsl:copy-of select="."/>
<xsl:apply-templates select="following-sibling::*[1]" mode="m1"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
The output of above XSLT transformation is following,
<?xml version="1.0" encoding="UTF-8"?>
<temp>
<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>
</temp>
--
Regards,
Mukul Gandhi
XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe<http://lists.mulberrytech.com/unsub/xsl-list/2963104> (by
email<>)
--~----------------------------------------------------------------
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
--~--