[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Is this a grouping task?

Subject: Re: Is this a grouping task?
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 22 Oct 2019 18:41:44 -0000
Re:  Is this a grouping task?
On 22.10.2019 20:07, Rick Quatro rick@xxxxxxxxxxxxxx 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.


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.