xsl-list
[Top] [All Lists]

Re: [xsl] We need to kick someone out of the group

2021-06-11 07:35:13

Am 11.06.2021 um 14:26 schrieb Charles O'Connor 
coconnor(_at_)ariessys(_dot_)com:
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>.




I would use group-starting-with in a template matching the parent or
node e.g.


   <xsl:template match="*[contrib-group]">
        <xsl:copy>
            <xsl:for-each-group select="*" group-starting-with="contrib-group">
                    <xsl:copy>
                        <xsl:apply-templates select="@*, node(), 
tail(current-group())"/>
                    </xsl:copy>
            </xsl:for-each-group>
        </xsl:copy>
    </xsl:template>


    <xsl:template match="aff/label"/>


Assumes the identity template set up. tail(current-group()) is 
subsequence(current-group(), 2) in XSLT 2.
--~----------------------------------------------------------------
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
--~--


<Prev in Thread] Current Thread [Next in Thread>