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

RE: Sort multiple xml files with identical keys

Subject: RE: Sort multiple xml files with identical keys
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 1 Mar 2006 14:40:33 -0000
xslt key multiple documents
The Muenchian method doesn't work well across multiple documents, because
key() only works within one document at a time. Best approach is to combine
the documents first, then do the grouping.

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

> -----Original Message-----
> From: Tapio.Niva@xxxxxxxxxxxxxxx [mailto:Tapio.Niva@xxxxxxxxxxxxxxx] 
> Sent: 01 March 2006 13:51
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Sort multiple xml files with identical keys
> 
> Hello,
> I'm using IE6 & MSXML to transform,sort and count 2 separate xml docs,
> but the results are not as I expected.
> As a beginner, I obviously have understood something wrong, I'm using
> the so-called "Muenchian method" here (...wtg for the XSLT 
> 2.0 to MSXML)
> I would be very appreciated if some xslt expert could give me a clue
> what I'm doing wrong.
> 
> Below are xml, xsl, results I got and results I wanted :
> -------------------------
> net_sample1.xml:
> <?xml version="1.0" encoding="UTF-8"?>				
> <?xml-stylesheet type="text/xsl" href="net_sample.xsl"?>		
> <List>	
> 	<row>
> 		<row_id>A1</row_id>
> 		<row_status>New</row_status>
> 	</row>
> 	<row>
> 		<row_id>A2</row_id>
> 		<row_status>New</row_status>
> 	</row>
> 	<row>
> 		<row_id>A2</row_id>
> 		<row_status>Old</row_status>
> 	</row>
> </List>
> -------------------------
> net_sample2.xml:
> <?xml version="1.0" encoding="UTF-8"?>				
> <?xml-stylesheet type="text/xsl" href="net_sample.xsl"?>		
> <List>	
> 	<row>
> 		<row_id>A1</row_id>
> 		<row_status>New</row_status>
> 	</row>
> 	<row>
> 		<row_id>A1</row_id>
> 		<row_status>New</row_status>
> 	</row>
> 	<row>
> 		<row_id>A2</row_id>
> 		<row_status>Old</row_status>
> 	</row>
> </List>
> ------------------------
> net_sample.xsl :
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
> <xsl:key name="rowkey"   	match="row"
> use="row_id" />
> <xsl:key name="rowkey_old"  	match="row[row_status='Old']"
> use="row_id" />
> <xsl:key name="rowkey_new"  	match="row[row_status='New']"
> use="row_id" />
> <xsl:template match="/">
> <html>
> <head></head>
> <body>
> <xsl:variable name="all_docs" select="document('net_sample1.xml'
> )/List/row | document('net_sample2.xml' )/List/row "/>	 
> <table border="0" bgcolor="ivory">
> <xsl:for-each select="$all_docs">
>  <xsl:sort select="row_id"/>
>    <xsl:for-each select="current()[count(. | key('rowkey', 
> row_id)[1]) =
> 1]"> 	
>    <tr>
>     <td><xsl:value-of select="row_id"/></td>		
>     <th>Old rows = </th>
>     <td><xsl:value-of select="count( key('rowkey_old',row_id) 
> )"/></td>
>     <th>New rows = </th>
>     <td><xsl:value-of select="count( key('rowkey_new',row_id) 
> )"/></td>
>    </tr>
>   </xsl:for-each>
> </xsl:for-each>
> </table>
> </body>
> </html>
> </xsl:template>	
> </xsl:stylesheet>
> ------------
> Result:
> A1	Old rows=0 New rows=1
> A1	Old rows=0 New rows=2
> A2	Old rows=1 New rows=1
> A2	Old rows=1 New rows=0
> ------------------------------------------
> The result I expected to see  :
> A1	Old rows=0 New rows=3
> A2	Old rows=2 New rows=1
> 
> Any ideas how to reach the wanted result ?
> 
> Regards, Tapio

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.