Re: [xsl] Total occurences and ordered display of XML elements

Subject: Re: [xsl] Total occurences and ordered display of XML elements
From: Rolando Isidoro <rli@xxxxxxxxxx>
Date: Wed, 14 Sep 2005 18:05:25 +0100
Following the message I sent earlier, I've been searching the web and reading books on the subject, but I haven't been able to solve my problem.
At http://gris-public.uninova.pt/CWIS/SPT--OAI.php?verb=ListRecords&metadataPrefix=oai_dc&set=Creator:Ricardo+J.+Goncalves is located an example of the XML I'm working on.


For writing a table with the total number of existing records on a given subject, as shown in following diagram,

----------------------------------------
| Authored book                    | 2 |
| Chapter in book                  | 2 |
| Papers in conference proceedings | 1 |
----------------------------------------

I tried something like this in the XSL file:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:fo="http://www.w3.org/1999/XSL/Format";
xmlns:xs="http://www.w3.org/2001/XMLSchema";
xmlns:fn="http://www.w3.org/2005/02/xpath-functions";

xmlns:dc="http://purl.org/dc/elements/1.1/";
xmlns:def="http://www.openarchives.org/OAI/2.0/";>

   <xsl:output method="xhtml" encoding="UTF-8" indent="yes"/>
   <xsl:template match="/">
       <html>
           <head>
               <title/>
           </head>
           <body>
               <table>
                   <tbody>
                       <tr>
                           <td>
                           Categories:
                       </td>
                       </tr>

<xsl:for-each select="fn:distinct-values(//dc:subject)"> (1)
<tr>
<td>
<xsl:value-of select="."/>
</td>
<td>
<xsl:value-of>fn:count(//def:record[def:metadata//dc:subject="."])</xsl:value-of> (2)
</td>
</tr>
</xsl:for-each>


                   </tbody>
               </table>
           </body>
       </html>
   </xsl:template>
</xsl:stylesheet>

I'm using XMLSpy as my source editor, and using the "Evaluate Xpath" tool the query "distinct-values(//dc:subject)" returns the correct results, i.e., "Authored book", "Chapter in book" and "Papers in conference proceedings", but when testing the transformation through the XSL debugger the line marked with (1) doesn't return any result. The same happens with (2), though in the "Evaluate Xpath" tool the query "count(//record[metadata//dc:subject="Authored book"])" correctly returns 2. I haven't been able to figure out what I'm doing wrong.

Any help is welcome, regards,
Rolando

Current Thread