xsl-list
[Top] [All Lists]

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

2016-08-23 09:43:36
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(_at_)gmail(_dot_)com> 
wrote:


Dear All,

I have hit upon something that already seems to have been discussed and
fixed. I am using  SaxonEE9-7-0-7J​ .. 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


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