0
votes

I have a XSL-File which has been written for being used with a XSLT 2.0 Transformer, but now I need to change the file in order to make it work with XSLT 1.0. I know the for-each-group-command is a XSLT 2.0 feature, but what about all the other things? How would I change my file to make it work with 1.0?

Here's the XSL-File:

<xsl:template match="ROWSET">

    <ROWSET>
        <xsl:for-each-group select="ROW" group-by="UKID">
            <UEBERKUNDE>
                <NAME><xsl:value-of select="UEBERKUNDE" /></NAME>
                <xsl:copy-of select="UKID" />
                <xsl:for-each-group select="current-group()" group-by="KUNDENNR">
                    <KUNDE>
                        <xsl:copy-of select="KUNDENNR" />
                        <xsl:copy-of select="KNAME1" />
                        <xsl:copy-of select="KNAME2" />
                        <xsl:copy-of select="KNAME3" />
                        <xsl:copy-of select="LAND" />
                        <xsl:copy-of select="PLZ" />
                        <xsl:copy-of select="ORT" />
                        <xsl:copy-of select="ADM" />
                        <xsl:copy-of select="KUNDENKLASSE" />
                        <xsl:copy-of select="MITARBEITER" />
                        <xsl:copy-of select="BELEGART" />
                        <EFAKTURA><xsl:value-of select="normalize-space(EFAKTURA)" /></EFAKTURA>
                        <WEBSTATUS><xsl:value-of select="normalize-space(WEBSTATUS)" /></WEBSTATUS>
                        <ZAHLUNGSBEDINGUNG><xsl:value-of select="normalize-space(ZAHLUNGSBEDINUNG)" /></ZAHLUNGSBEDINGUNG>

                        <xsl:for-each select="current-group()[count(. | key('rowsByMonth', concat(MONAT,'+',JAHR,'+',KUNDENNR))[1]) = 1]">
                            <ROW>
                                <xsl:copy-of select="JAHR" />
                                <xsl:copy-of select="MONAT" />
                                <xsl:copy-of select="HANDLING" />
                                <xsl:copy-of select="SOLLFRACHT" />
                                <xsl:for-each select="key('rowsByMonth', concat(MONAT,'+',JAHR,'+',KUNDENNR))">
                                    <WARENGRUPPE>
                                        <xsl:copy-of select="HGNAME" />
                                        <xsl:copy-of select="HGID" />
                                        <xsl:copy-of select="DG_BASIS" />
                                        <xsl:copy-of select="EKECHT" />
                                        <xsl:copy-of select="DB_BASIS" />
                                        <xsl:copy-of select="NETTO" />
                                    </WARENGRUPPE>
                                </xsl:for-each>
                            </ROW>
                        </xsl:for-each>
                    </KUNDE>
                </xsl:for-each-group>
            </UEBERKUNDE>
        </xsl:for-each-group>
    </ROWSET>
</xsl:template></xsl:stylesheet>

Thanks in advance!

1
The snippet you've provided doesn't seem to have any 2.0-only features besides for-each-group and its counterpart current-group().JLRishe
So how would I change the for-each-group to keep it working?gasparuff
The use of key() in the middle indicates that what you have is a hybrid of XSLT 1.0 techniques (Muenchian method of sorting) and XSLT 2.0 (for-each-group). That makes the conversion not so straightforward since it is unclear the intention of the key(). When I need to do nested grouping I use the variable-based grouping method (Google: XSLT variable-based grouping method).G. Ken Holman

1 Answers

0
votes

If you want to do grouping in XSLT 1.0 then see http://www.jenitennison.com/xslt/grouping/muenchian.xml for simply "group by" and http://www.biglist.com/lists/xsl-list/archives/200101/msg00070.html for nested grouping.

So

<ROWSET>
    <xsl:for-each-group select="ROW" group-by="UKID">
        <UEBERKUNDE>
            <NAME><xsl:value-of select="UEBERKUNDE" /></NAME>
            <xsl:copy-of select="UKID" />
            <xsl:for-each-group select="current-group()" group-by="KUNDENNR">

roughly translate into two keys

<xsl:key name="by-ukid" match="ROW" use="UKID"/>

<xsl:key name="by-nr" match="ROW" use="concat(UKID, '|', KUNDENNR)"/>

and

<ROWSET>
    <xsl:for-each select="ROW[generate-id() = generate-id(key('by-ukid',UKID)[1])]">
        <UEBERKUNDE>
            <NAME><xsl:value-of select="UEBERKUNDE" /></NAME>
            <xsl:copy-of select="UKID" />
            <xsl:for-each select="key('by-ukid', UKID)[generate-id() = generate-id(key('by-nr', concat(UKID, '|', KUNDENNR))[1])]">

If you have further nested grouping you need more keys with concatenated key values.