[xsl] Re: Xsl for each group issue in streaming mode

Subject: [xsl] Re: Xsl for each group issue in streaming mode
From: "Mailing Lists Mail daktapaal@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 23 Aug 2016 14:43:28 -0000
Posted this on saxon list yesterday. Not sure if my post was successful..
so posting it here.. in case people in this list want to test and check..

On Aug 22, 2016 12:07 PM, "Mailing Lists Mail" <daktapaal@xxxxxxxxx> wrote:

>
> Dear All,
>
> I have hit upon something that already seems to have been discussed and
> fixed. I am using  SaxonEE9-7-0-7Jb .. For this simple Case below. The
> <RootNode> is missing the end element </RootNode>
>
> XML:
>
> <RootNode>
> <Groups>
> <Group>
> <specifics>
> <specific>Subgroup1</specific>
> <specific>Subgroup2</specific>
> </specifics>
> <Group_Detail>
> <GroupIdentifier>G1</GroupIdentifier>
> </Group_Detail>
> </Group>
> <Group>
> <specifics>
> <specific>Subgroup3</specific>
> <specific>Subgroup4</specific>
> </specifics>
> <Group_Detail>
> <GroupIdentifier>G1</GroupIdentifier>
> </Group_Detail>
> </Group>
> <Group>
> <specifics>
> <specific>Subgroup1</specific>
> <specific>Subgroup2</specific>
> </specifics>
> <Group_Detail>
> <GroupIdentifier>G2</GroupIdentifier>
> </Group_Detail>
> </Group>
> <Group>
> <specifics>
> <specific>Subgroup5</specific>
> <specific>Subgroup6</specific>
> </specifics>
> <Group_Detail>
> <GroupIdentifier>G2</GroupIdentifier>
> </Group_Detail>
> </Group>
> </Groups>
> </RootNode>
>
> XSLT
>
> <xsl:transform version="3.0" xmlns:xsl="http://www.w3.org/
> 1999/XSL/Transform">
> <xsl:mode name="stream" streamable="yes" on-no-match="shallow-copy"/>
> <xsl:output method="xml" indent="yes"/>
> <!--Define Global Variables by Streaming Input XML -->
> <xsl:param name="fileHref" select="'file:///p:/Developers/perf/xslt3/For-
> EachGroup-Issue.xml'"/>
> <xsl:variable name="outDir" select="substring-before($fileHref,
> tokenize($fileHref,'/')[last()])"/>
> <xsl:variable name="OutFileName" select="substring-before($fileHref,'.xml')
> || '-Formatted.xml'"/>
> <xsl:template match="/">
> <xsl:result-document href="{$OutFileName}">
> <xsl:stream href="{$fileHref}">
> <xsl:apply-templates mode="stream"/>
> </xsl:stream>
> </xsl:result-document>
> </xsl:template>
> <xsl:template match="Groups" mode="stream">
> <xsl:copy>
> <xsl:for-each-group select="Group/copy-of(.)" group-by="Group_Detail/
> GroupIdentifier">
> <xsl:variable name="GroupDetail" select="Group_Detail/copy-of(.)"/>
> <xsl:variable name="groupId" select="$GroupDetail/GroupIdentifier"/>
> <Formatted-Group groupId="{$groupId}">
> <xsl:copy-of select="current-group()/specifics"/>
> </Formatted-Group>
> </xsl:for-each-group>
> </xsl:copy>
> </xsl:template>
> </xsl:transform>
>
> Result:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!-- See missing </RootNode> -->
> <RootNode>
>  <Groups>
>   <Formatted-Group groupId="G1">
>      <specifics>
>  <specific>Subgroup1</specific>
>  <specific>Subgroup2</specific>
> </specifics>
> <specifics>
> <specific>Subgroup3</specific>
>  <specific>Subgroup4</specific>
>  </specifics>
> </Formatted-Group>
> <Formatted-Group groupId="G3">
> <specifics>
>  <specific>Subgroup1</specific>
> <specific>Subgroup2</specific>
>  </specifics>
>  <specifics>
>  <specific>Subgroup3</specific>
> <specific>Subgroup4</specific>
> </specifics>
> </Formatted-Group>
> <Formatted-Group groupId="G2">
>  <specifics>
> <specific>Subgroup5</specific>
>  <specific>Subgroup6</specific>
> </specifics>
> </Formatted-Group>
>  </Groups>
>
> Best Regards, Dak Tapaal

Current Thread