Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] Sort multiple xml files with identical keys

From: "Michael Kay" <mike@------------>
To:
Date: 3/1/2006 2:41:00 PM
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: [xsl] 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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent