Altova Mailing List Archives>Archive Index >xsl-list Archive Home >Recent entries >Thread Prev - [xsl] Sort multiple xml files with identical keys [Thread Next] Re: [xsl] Sort multiple xml files with identical keysTo: Date: 3/1/2006 2:21:00 PM At 2006-03-01 15:51 +0200, Tapio.Niva@xxxxxxxxxxxxxxx wrote: 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) The Muenchian method works only in a single document context. I've posted before about using variable-based grouping across multiple documents: http://www.biglist.com/lists/xsl-list/archives/200410/msg00412.html In our hands-on training for XSLT 1.0 (next one in less than two weeks) we cover three ways of doing grouping: axis-based, key-based, and variable-based ... each have their place in document transformation solutions. Axis-based is good for the adjacent context (hiding adjacent duplicates), key-based is good for a document-wide context, and variable-based is good for either sub-document context or a multiple-document context. I hope the answer below helps. . . . . . . . . . . . Ken T:\ftemp>type 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> T:\ftemp>type 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> T:\ftemp>xslt tapio.xsl tapio.xsl con A1 Old rows=0 New rows=3 A2 Old rows=2 New rows=1 T:\ftemp>type tapio.xsl <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:variable name="all_docs" select="document('net_sample1.xml')/List/row | document('net_sample2.xml')/List/row "/> <xsl:for-each select="$all_docs"> <xsl:if test="generate-id(.)= generate-id($all_docs[row_id=current()/row_id][1])"> <xsl:value-of select="row_id"/> <xsl:text> Old rows=</xsl:text> <xsl:value-of select="count($all_docs[row_id=current()/row_id] [row_status='Old'])"/> <xsl:text> New rows=</xsl:text> <xsl:value-of select="count($all_docs[row_id=current()/row_id] [row_status='New'])"/> <xsl:text> </xsl:text> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet> T:\ftemp> -- Upcoming XSLT/XSL-FO hands-on courses: Washington,DC 2006-03-13/17 World-wide on-site corporate, govt. & user group XML/XSL training. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
