xsl-list
[Top] [All Lists]

Re: [xsl] Is this a grouping task?

2019-10-22 13:41:48
On 22.10.2019 20:07, Rick Quatro rick(_at_)rickquatro(_dot_)com wrote:

I am using XSLT 2 and think this may require a for-each-group solution.
Any advice would be appreciated. Thank you very much.

As an alternative, if you can move to XSLT 3, then I think it is also
easy with "xsl:iterate":

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:xs="http://www.w3.org/2001/XMLSchema";
    exclude-result-prefixes="#all"
    version="3.0">

    <xsl:mode on-no-match="shallow-copy" streamable="yes"/>

    <xsl:mode name="rev-change" on-no-match="shallow-copy"
streamable="yes"/>

    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="topic">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:iterate select="*">
                <xsl:param name="rev-change" as="xs:boolean"
select="false()"/>
                <xsl:apply-templates select="." mode="rev-change">
                    <xsl:with-param name="rev-change"
select="$rev-change" tunnel="yes"/>
                </xsl:apply-templates>
                <xsl:next-iteration>
                    <xsl:with-param name="rev-change"
                        select="if (self::revst) then true()
                        else if (self::revend) then false()
                        else $rev-change"/>
                </xsl:next-iteration>
            </xsl:iterate>
        </xsl:copy>
    </xsl:template>

    <xsl:template mode="rev-change" match="topic/*">
        <xsl:param name="rev-change" tunnel="yes"/>
        <xsl:copy>
            <xsl:if test="$rev-change">
                <xsl:attribute name="rev">changed</xsl:attribute>
            </xsl:if>
            <xsl:apply-templates select="@*" mode="#current"/>
            <xsl:apply-templates mode="#current"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template mode="rev-change" match="revst | revend" priority="2"/>

</xsl:stylesheet>


Even works with streaming if you use Saxon 9.8 or 9.9 EE.
--~----------------------------------------------------------------
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>