This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Multiple xml trasformation
- To: XSL List <xsl-list at lists dot mulberrytech dot com>
- Subject: Re: [xsl] Multiple xml trasformation
- From: Joerg Pietschmann <joerg dot pietschmann at zkb dot ch>
- Date: Wed, 22 Aug 2001 17:56:31 +0200
- Organization: ZKB
- Reply-To: xsl-list at lists dot mulberrytech dot com
"Jozef Palocko" <jpalocko@SandboxSecurity.cz> 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