xsl-list
[Top] [All Lists]

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

2021-06-11 07:42:18
Charles,

Your stated input has:

<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>

So, we must inquire, those aff elements are loose? In other words, you do
not have the case

<aff id="aff1">Kingdom of Curds</aff>

with an explicit id/rid link?

Or if not, is such linking implicit (i.e. Bob really is from Curds, and you
want to move the aff to reflect this)?

Because if so (depending on your inputs) it might be more robust to build a
key and work that way.

Meanwhile I see Martin H has given an answer to the question actually
posed. :-)

My own tastes go to very clean beers, such as Pilsner or Koelsch. Of course
the great thing about beer is, we all get to please ourselves.

Regards, Wendell






On Fri, Jun 11, 2021 at 8:26 AM Charles O'Connor 
coconnor(_at_)ariessys(_dot_)com <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

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






-- 
...Wendell Piez... ...wendell -at- nist -dot- gov...
...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org...
...github.com/wendellpiez... ...gitlab.coko.foundation/wendell...
--~----------------------------------------------------------------
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>