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

RE: Use for-each-group to eliminate duplicate output

Subject: RE: Use for-each-group to eliminate duplicate output nodes?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 22 Dec 2005 00:23:16 -0000
xslt eliminate duplicates
I haven't studied the logic in detail, but:

(a) You need to think of this as a multiphase transformation. Your existing
code is phase 1, the deduplication is phase 2. 

(b) The output of the first phase will need to be structured as XML, at the
moment it's plain text

(c) Deduplication using xsl:for-each-group (or possibly even using the
simpler distinct-values()) should then be unproblematic. 

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: cknell@xxxxxxxxxx [mailto:cknell@xxxxxxxxxx] 
> Sent: 21 December 2005 18:11
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Use for-each-group to eliminate duplicate output nodes?
> 
> I have a transformation during which I'd like to eliminate 
> some duplicate nodes which are generated in the 
> transformation. Below is a sample of a portion of the input 
> document the relevant templates from the XSLT document and 
> the output currently generated.
> 
> I need to eliminate duplicate lines from the output file. If 
> I were post-processing with perl, I'd use a hash to do this. 
> Now that I'm moving into XSLT 2.0, I have the feeling that 
> something similar to a perl hash can be got using 
> <xsl:for-each-group>.
> 
> The actual stylesheet and data document are somewhat more 
> complicated. I hope that I have steered correctly between the 
> Scylla and Charybdis of too much and too little information. 
> Can someone tell me whether <xsl:for-each-group> can be used 
> like a perl hash to eliminate duplicate values, and if so how? Thanks.
> 
> -- Data Document (sample portion)--
> <path>
> <node type="process" id="023">
>   <predecessors>
>      <node type="process" id="020">
>         <predecessors>
>            <node type="process" id="001">
>               <predecessors>
>                  <node type="data-store" id="058"/>
>               </predecessors>
>            </node>
>            <node type="process" id="002">
>               <predecessors>
>                  <node type="data-store" id="059"/>
>               </predecessors>
>            </node>
>         </predecessors>
>      </node>
>   </predecessors>
> </node>
> 
> <node type="process" id="024">
>   <predecessors>
>      <node type="process" id="020">
>         <predecessors>
>            <node type="process" id="001">
>               <predecessors>
>                  <node type="data-store" id="058"/>
>               </predecessors>
>            </node>
>            <node type="process" id="002">
>               <predecessors>
>                  <node type="data-store" id="059"/>
>               </predecessors>
>            </node>
>         </predecessors>
>      </node>
>    </predecessors>
> </node>
> </path>
> 
> These are the templates that process the part of the document shown.:
> 
> -- XSLT document --
> <xsl:template match="/">
>   digraph d{
>   <xsl:apply-templates />
> 		}
> </xsl:template>
> 
> <xsl:template match="path">
>   node_<xsl:value-of select="node/@id" /> ;
>   <xsl:apply-templates mode="set-nodes" />
>   <xsl:apply-templates mode="set-connections" />
> </xsl:template>
> 
> <xsl:template match="predecessors" mode="set-nodes">
>   <xsl:apply-templates mode="set-nodes" />
> </xsl:template>
> 
> <xsl:template match="node" mode="set-nodes">
>   <xsl:apply-templates mode="set-nodes" />
> </xsl:template>
> 
> <xsl:template match="predecessors/node" mode="set-nodes">
>   node_<xsl:value-of select="@id" />
>   <xsl:apply-templates mode="set-nodes" />
> </xsl:template>
> 
> <xsl:template match="node" mode="set-connections">
>   <xsl:variable name="target-node" select="." />
>   <xsl:for-each select="predecessors/node">
>     node_<xsl:value-of select="@id" /> -> node_<xsl:value-of 
> select="$target-node/@id" />
>   </xsl:for-each>
>   <xsl:apply-templates mode="set-connections" />
> </xsl:template>
> 
> Output from existing stylesheet (sorted to make 
> identification of duplicates easier):
> 
> digraph d{
> 	node_001
> 	node_001
> 	node_002
> 	node_002
> 	node_003
> 	node_003
> 	node_004
> 	node_005
> 	node_006
> 	node_007
> 	node_008
> 	node_020
> 	node_020
> 	node_023
> 	node_024
> 	node_028
> 	node_038
> 	node_058
> 	node_058
> 	node_059
> 	node_059
> 	node_060
> 	node_061
> 	node_062
> 	node_063
> 	node_064
> 	node_065
> 
> 	node_001 -> node_020
> 	node_001 -> node_020
> 	node_002 -> node_020
> 	node_002 -> node_020
> 	node_004 -> node_038
> 	node_005 -> node_038
> 	node_006 -> node_038
> 	node_007 -> node_038
> 	node_008 -> node_038
> 	node_020 -> node_023
> 	node_020 -> node_024
> 	node_023 -> node_038
> 	node_024 -> node_038
> 	node_038 -> node_028
> 	node_058 -> node_001
> 	node_058 -> node_001
> 	node_059 -> node_002
> 	node_059 -> node_002
> 	node_060 -> node_003
> 	node_061 -> node_004
> 	node_062 -> node_005
> 	node_063 -> node_006
> 	node_064 -> node_007
> 	node_065 -> node_008
> }
> -- 
> Charles Knell
> cknell@xxxxxxxxxx - email

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.