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

Re: Multiple xml trasformation

Subject: Re: Multiple xml trasformation
From: Joerg Pietschmann <joerg.pietschmann@xxxxxx>
Date: Wed, 22 Aug 2001 17:56:31 +0200
xsl count distinct
"Jozef Palocko" <jpalocko@xxxxxxxxxxxxxxxxxx> wrote
> 
> Hi, I have question: 
> I have many XML documents of the same format like this 
> <Entries> 
>     <Entry>...</Entry> 
>      <Entry>...</Entry> 
>     ... 
> </Entries>. 
> 
> I'm using muenchian method to select distinct entries from file and
> display 
> its count. 
> 
> And question is: 
> How can I count distinct entries from multiple xml files ? 
> Is some way how to merge these xml files to one source and then perform 
> tranformation or something else how solve this problem? 

Merging the files into an intermediate file or into avariable and
access the value using a node-set() extension function definitely
simplifies the task.

Another aproach might be building a union:

  <xsl:variable name="entries"
    select="document('doc1')/*/Entry|document('doc1')/*/Entry"/>

or if you have an XML document with the file names:

  <files>
    <file>doc1</file>
    <file>doc2</file>
  </files>

you can take advantage of the fact that the first argument to document
may be a node set:

  <xsl:variable name="entries" select="document(files/file)/*/Entry"/>

You should then be able to iterate over the node set an process only
unique entries:

  <xsl:for-each select="$entries">
    <xsl:if test=generate-id()=generate-id($entries[.=current()][1])>
      <!-- do something -->
    </xsl:if>
  </xsl:for-each>

If you only want to count unique entries, use the code above to build
a string variable which contains a character for each unique entry:

  <xsl:variable name="entry-count">
    <xsl:for-each select="$entries">
      <xsl:if test=generate-id()=generate-id($entries[.=current()][1])>
       <xsl:text>1</xsl:text>
      </xsl:if>
    </xsl:for-each>
  </xsl:variable>
  <xsl:value-of select="string-length($entry-count)"/>

Competely untested.
As you already noted there is no elegant way to select unique entries because
neither the preceding axis nor keys work across documents.
Just the example using node-set:

  <xsl:variable name="entries">
    <xsl:for-each select="document(files/file)/*/Entry"/>
      <xsl:copy-of select="."/>
    </xsl:for-each>
  </xsl:variable>

  <xsl:value-of select="count(xx:node-set($entries)/Entry[not(.=preceding::Entry)])"/>

Also untested.
The xx prefix is processor specific, look into the manuals how to handle it.

HTH
J.Pietschmann

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.