You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Good Dan-dgood01 <Da...@motorola.com> on 2003/04/16 12:49:38 UTC
Counting in xslt
I've got this xml document:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Count.xslt"?>
<Topology xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Manager Name="John">
<Employee ID="101" Department="d2"/>
<Employee ID="103" Department="d1"/>
<Employee ID="108" Department="d1"/>
<Employee ID="102" Department="d4"/>
<Employee ID="119" Department="d2"/>
<Employee ID="111" Department="d4"/>
</Manager>
<Manager Name="Robin">
<Employee ID="130" Department="d11"/>
<Employee ID="107" Department="d11"/>
<Employee ID="133" Department="d41"/>
<Employee ID="118" Department="d11"/>
<Employee ID="144" Department="d41"/>
<Employee ID="118" Department="D7"/>
<Employee ID="144" Department="D7"/>
</Manager>
<Organisation Dept="d1"/>
<Organisation Dept="d2"/>
<Organisation Dept="d4"/>
<Organisation Dept="d7"/>
<Organisation Dept="d11"/>
<Organisation Dept="D41"/>
</Topology>
and here's a simplified version of my stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="Topology/Manager"/>
</xsl:template>
<xsl:template match="Topology/Manager">
<xsl:value-of select="count(//Topology/Organisation[@Dept=current()/Employee/@Department])"/>
</xsl:template>
</xsl:stylesheet>
It counts the number of different Departments underneath each Manager element. For example "John" has "d2", "d1", and "d4", therefore count returns 3. For "Robin" it should return 3 but only returns 1.
The problem is that the value of attribute Department or Dept could be uppercase or lowercase but I would like to treat "D41" and "d41" as the same value.
Does anyone know how I can do this, or can you think of another way of counting? Is there a unique function or anything like that?
Any help appreciated,
Dan
Re: Counting in xslt
Posted by Joseph Kesselman <ke...@us.ibm.com>.
Classic solution would be to fold the values to a single case before
comparing them. I'm having trouble accessing the spec right now, but
there's probably something in the XSLT function library which would
accomplish this...
______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"may'ron DaroQbe'chugh vaj bIrIQbej" ("Put down the squeezebox and nobody
gets hurt.")