[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: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 01 Mar 2006 09:20:07 -0500
multiple select box sort
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

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-2007 All Rights Reserved.