Subject: Re: [xsl] Multiple xml trasformation From: Joerg Pietschmann <joerg.pietschmann@xxxxxx> Date: Wed, 22 Aug 2001 17:56:31 +0200 |
"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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Multiple xml trasformation, Jozef Palocko | Thread | [xsl] using XSLT to transform a XML, Svend Ezaki Tofte |
RE: [xsl] XMLDOM xml to html transl, Chris Bayes | Date | [xsl] namespace and XPath question, partner com |
Month |