Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: "G. Ken Holman" <gkholman@-------------------->
To:
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


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