Subjects
Home
Xalan extension functions
Fomatting question serializing DOM with pretty print
xalan with pull parser
Cannot find the declaration
Apache Xalan drop support to run on JRE 1 1 x
Why does Doctype change processing of a document
Node set to XML string via Java extensions in Xalan J: possible?
Templates/Transformers + thread safety???
Problem evaluating xpath with muliple prefix with different namespace
remove an arbitrary attribute from xsl output
Xalan3 XSLT 2 0 XPath 2 0 support?
Problem using compiled translets with Xalan !!
Xalan and jstl 1 1 problem with transform tag
NullPointer in DOM2DTM getLocalName
URIResolvers base parameter with xsltc and cascaded imports
Performance problem for Xalan J on intel dual core
Standard libraries in JAXP?
Serializing a DOM tree to XML file, customize entities replacement
Library Conflict Involving BCEL Library
A question on how users are using <xsl:message >
Kevin Cormier as a new Apache Xalan J committer
Struggling to iterate over tokenized string
Xalan count() trouble
Problem with recursive xpath
Error when switching to java 1 5
document( ' ')
Problem with Xalan2 7 0 transformation
cr/lf options
entity encoded XML
can xalan transform 2 xml using one xslt?
Xalan J JIRA defect review Monday October 16, 2006 from 2:00 to 3:30 pm ED
xsl transform with cdata section elements
xslt parameters not expanded
Weird behavior of XPath evaluate()
How to avoid <xsl:message > instruction prints stylesheet file informations ?
Cannot find SimpleTransform subdirectory after installing Xalan J
recover from document not found exceptions
jdk1 5 and Xalan jar differences?
Performance Issue
Error/Bug adding floating point numbers
XPathAPI: eval exp using nodes with default namespace
modifying xalan to output invalid XML
NullPointerException
mege two separate xml nodes into one
Is this a XALAN document identification bug?
is StylesheetRoot really java io Serializable ?
transform() fails for DOMSource but succeeds for StreamSource
Thoughts on Transformer parameter passing
HELP, Xalan and jstl 1 1 problem with transformer
Problem with XPath namespace axis?
string utils:replace deleting search string if replacement string is an HTML
help with enumeration values pls
xalan 2 5 1 vs 2 7 performance question
How to insert/update in XML document
HTML Serialization and Handling of Ampersands in HREF Attributes
XHTML link tag stripping
SystemId Unknown; Line #24; Column #49; java lang NullPointerException
xpath text() help
Apostrophe problem with xalan 2 7 0
How to set variables in XML document?
Links
Home
Oracle database error code ...
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
Counting in xslt

Counting in xslt

2003-04-16       - By Good Dan-dgood01
Reply:     1     2     3     4     5  

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[@(protected)=current()/Employee/
@(protected)])"/>
</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


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 5.50.4919.2200" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Arial size=2><SPAN class=800170510-16042003>I've got this xml
document:</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=800170510-16042003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=2><SPAN class=800170510-16042003><FONT color=#008080
size=1><FONT face=Arial color=#000000 size=2><FONT color=#008080 size=1><FONT
color=#000000 size=2>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</FONT></DIV>
<DIV><FONT color=#000000 size=2>&lt;?xml-stylesheet type="text/xsl"
href="Count.xslt"?&gt;</FONT></DIV></FONT>
<DIV>&lt;Topology xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance<FONT
color=#0000ff size=1><FONT color=#000000 size=2>"&gt;</FONT></DIV></FONT><FONT
color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Manager</FONT><FONT color=#ff0000> Name</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>John</FONT><FONT color=#0000ff
size=1><FONT size=2>"&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Employee</FONT><FONT color=#ff0000> ID</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>101</FONT><FONT
color=#0000ff>"</FONT><FONT color=#ff0000> Department</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>d2</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Employee</FONT><FONT color=#ff0000> ID</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>103</FONT><FONT
color=#0000ff>"</FONT><FONT color=#ff0000> Department</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>d1</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Employee</FONT><FONT color=#ff0000> ID</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>108</FONT><FONT
color=#0000ff>"</FONT><FONT color=#ff0000> Department</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>d1</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Employee</FONT><FONT color=#ff0000> ID</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>102</FONT><FONT
color=#0000ff>"</FONT><FONT color=#ff0000> Department</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>d4</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Employee</FONT><FONT color=#ff0000> ID</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>119</FONT><FONT
color=#0000ff>"</FONT><FONT color=#ff0000> Department</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>d2</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Employee</FONT><FONT color=#ff0000> ID</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>111</FONT><FONT
color=#0000ff>"</FONT><FONT color=#ff0000> Department</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>d4</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;/</FONT><FONT
color=#800000>Manager</FONT><FONT color=#0000ff size=1><FONT
size=2>&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Manager</FONT><FONT color=#ff0000> Name</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>Robin</FONT><FONT color=#0000ff
size=1><FONT size=2>"&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Employee</FONT><FONT color=#ff0000> ID</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>130</FONT><FONT
color=#0000ff>"</FONT><FONT color=#ff0000> Department</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>d11</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Employee</FONT><FONT color=#ff0000> ID</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>107</FONT><FONT
color=#0000ff>"</FONT><FONT color=#ff0000> Department</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>d11</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Employee</FONT><FONT color=#ff0000> ID</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>133</FONT><FONT
color=#0000ff>"</FONT><FONT color=#ff0000> Department</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>d41</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Employee</FONT><FONT color=#ff0000> ID</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>118</FONT><FONT
color=#0000ff>"</FONT><FONT color=#ff0000> Department</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>d11</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Employee</FONT><FONT color=#ff0000> ID</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>144</FONT><FONT
color=#0000ff>"</FONT><FONT color=#ff0000> Department</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>d41</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Employee</FONT><FONT color=#ff0000> ID</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>118</FONT><FONT
color=#0000ff>"</FONT><FONT color=#ff0000> Department</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>D7</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Employee</FONT><FONT color=#ff0000> ID</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>144</FONT><FONT
color=#0000ff>"</FONT><FONT color=#ff0000> Department</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>D7</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;/</FONT><FONT
color=#800000>Manager</FONT><FONT color=#0000ff size=1><FONT
size=2>&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Organisation</FONT><FONT color=#ff0000> Dept</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>d1</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Organisation</FONT><FONT color=#ff0000> Dept</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>d2</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Organisation</FONT><FONT color=#ff0000> Dept</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>d4</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Organisation</FONT><FONT color=#ff0000> Dept</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>d7</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Organisation</FONT><FONT color=#ff0000> Dept</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>d11</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT><FONT color=#000000>
<DIV></FONT><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>Organisation</FONT><FONT color=#ff0000> Dept</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>D41</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV>
<DIV><FONT color=#000000
size=2>&lt;/</FONT></FONT>Topology&gt;</DIV></FONT></FONT><FONT color=#0000ff
size=1><FONT color=#000000 size=2>
<DIV><FONT face=Arial><SPAN class=800170510-16042003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><SPAN class=800170510-16042003>and here's a simplified
version of my stylesheet:</SPAN></FONT></DIV>
<DIV><FONT face=Arial><SPAN class=800170510-16042003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=2><SPAN class=800170510-16042003><FONT color=#008080
size=1><FONT face=Arial color=#000000 size=2>&lt;?xml version="1.0"
encoding="UTF-8"?&gt;</FONT></DIV></FONT>
<DIV><FONT face=Arial>&lt;xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform<FONT color=#0000ff size=1><FONT
color=#000000 size=2>"&gt;</FONT></DIV></FONT></FONT><FONT color=#000000>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>xsl:output</FONT><FONT color=#ff0000> method</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>text</FONT><FONT
color=#0000ff>"</FONT><FONT color=#ff0000> version</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>1.0</FONT><FONT
color=#0000ff>"</FONT><FONT color=#ff0000> encoding</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>UTF-8</FONT><FONT
color=#0000ff>"</FONT><FONT color=#ff0000> indent</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>yes</FONT><FONT color=#0000ff
size=1><FONT size=2>"/&gt;</FONT></DIV></FONT></FONT><FONT color=#000000>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>xsl:template</FONT><FONT color=#ff0000> match</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>/</FONT><FONT color=#0000ff
size=1><FONT size=2>"&gt;</FONT></DIV></FONT></FONT><FONT color=#000000>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>xsl:apply-templates</FONT><FONT color=#ff0000> select</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>Topology/Manager</FONT><FONT
color=#0000ff size=1><FONT size=2>"/&gt;</FONT></DIV></FONT></FONT><FONT
color=#000000>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff>&lt;/</FONT><FONT
color=#800000>xsl:template</FONT><FONT color=#0000ff size=1><FONT
size=2>&gt;</FONT></DIV></FONT></FONT><FONT color=#000000>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>xsl:template</FONT><FONT color=#ff0000> match</FONT><FONT
color=#0000ff>="</FONT><FONT color=#000000>Topology/Manager</FONT><FONT
color=#0000ff size=1><FONT size=2>"&gt;</FONT></DIV></FONT></FONT><FONT
color=#000000>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff>&lt;</FONT><FONT
color=#800000>xsl:value-of</FONT><FONT color=#ff0000> select</FONT><FONT
color=#0000ff>="</FONT><FONT
color=#000000>count(//Topology/Organisation[@(protected)=current()/Employee/
@(protected)])</FONT><FONT
color=#0000ff size=1><FONT size=2>"/&gt;</FONT></DIV></FONT></FONT><FONT
color=#000000>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff>&lt;/</FONT><FONT
color=#800000>xsl:template</FONT></FONT><FONT color=#0000ff size=1><FONT
face=Arial size=2>&gt;</FONT></DIV>
<DIV><FONT face=Arial color=#000000 size=2>&lt;/</FONT></FONT><FONT
face=Arial>xsl:stylesheet</FONT><FONT color=#0000ff size=1><FONT face=Arial
color=#000000 size=2>&gt;</FONT></DIV>
<DIV><FONT face=Arial color=#000000
size=2></FONT></FONT></SPAN></FONT>&nbsp;</DIV>
<DIV><SPAN class=800170510-16042003><FONT face=Arial>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&nbsp;3 but only returns 1.</FONT></SPAN></DIV>
<DIV><SPAN class=800170510-16042003><FONT face=Arial></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=800170510-16042003><FONT face=Arial>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.</FONT></SPAN></DIV>
<DIV><SPAN class=800170510-16042003><FONT face=Arial></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=800170510-16042003><FONT face=Arial>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?</FONT></SPAN></DIV>
<DIV><SPAN class=800170510-16042003><FONT face=Arial></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=800170510-16042003><FONT face=Arial>Any help
appreciated,</FONT></SPAN></DIV>
<DIV><SPAN class=800170510-16042003><FONT face=Arial>Dan</FONT></SPAN></DIV>
<DIV><SPAN
class=800170510-16042003></SPAN>&nbsp;</DIV></FONT></FONT></SPAN></FONT></BODY>
</HTML>