  | |  | Counting in xslt | Counting in xslt 2003-04-16 - By Good Dan-dgood01
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> </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><?xml version="1.0" encoding="UTF-8"?></FONT></DIV> <DIV><FONT color=#000000 size=2><?xml-stylesheet type="text/xsl" href="Count.xslt"?></FONT></DIV></FONT> <DIV><Topology xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance<FONT color=#0000ff size=1><FONT color=#000000 size=2>"></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff></</FONT><FONT color=#800000>Manager</FONT><FONT color=#0000ff size=1><FONT size=2>></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff></</FONT><FONT color=#800000>Manager</FONT><FONT color=#0000ff size=1><FONT size=2>></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV></FONT><FONT color=#000000> <DIV></FONT><FONT color=#0000ff><</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>"/></FONT></DIV> <DIV><FONT color=#000000 size=2></</FONT></FONT>Topology></DIV></FONT></FONT><FONT color=#0000ff size=1><FONT color=#000000 size=2> <DIV><FONT face=Arial><SPAN class=800170510-16042003></SPAN></FONT> </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> </DIV> <DIV><FONT size=2><SPAN class=800170510-16042003><FONT color=#008080 size=1><FONT face=Arial color=#000000 size=2><?xml version="1.0" encoding="UTF-8"?></FONT></DIV></FONT> <DIV><FONT face=Arial><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform<FONT color=#0000ff size=1><FONT color=#000000 size=2>"></FONT></DIV></FONT></FONT><FONT color=#000000> <DIV></FONT><FONT face=Arial><FONT color=#0000ff><</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>"/></FONT></DIV></FONT></FONT><FONT color=#000000> <DIV></FONT><FONT face=Arial><FONT color=#0000ff><</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>"></FONT></DIV></FONT></FONT><FONT color=#000000> <DIV></FONT><FONT face=Arial><FONT color=#0000ff><</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>"/></FONT></DIV></FONT></FONT><FONT color=#000000> <DIV></FONT><FONT face=Arial><FONT color=#0000ff></</FONT><FONT color=#800000>xsl:template</FONT><FONT color=#0000ff size=1><FONT size=2>></FONT></DIV></FONT></FONT><FONT color=#000000> <DIV></FONT><FONT face=Arial><FONT color=#0000ff><</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>"></FONT></DIV></FONT></FONT><FONT color=#000000> <DIV></FONT><FONT face=Arial><FONT color=#0000ff><</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>"/></FONT></DIV></FONT></FONT><FONT color=#000000> <DIV></FONT><FONT face=Arial><FONT color=#0000ff></</FONT><FONT color=#800000>xsl:template</FONT></FONT><FONT color=#0000ff size=1><FONT face=Arial size=2>></FONT></DIV> <DIV><FONT face=Arial color=#000000 size=2></</FONT></FONT><FONT face=Arial>xsl:stylesheet</FONT><FONT color=#0000ff size=1><FONT face=Arial color=#000000 size=2>></FONT></DIV> <DIV><FONT face=Arial color=#000000 size=2></FONT></FONT></SPAN></FONT> </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 3 but only returns 1.</FONT></SPAN></DIV> <DIV><SPAN class=800170510-16042003><FONT face=Arial></FONT></SPAN> </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> </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> </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> </DIV></FONT></FONT></SPAN></FONT></BODY> </HTML>
|
|
 |