XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Liam BSubject: XSLT to Html problems
Author: Liam B
Date: 18 Dec 2008 04:45 AM
I'm developing some online organisation charts for my company.

The problem i have is these charts can be very wide with a lot of horizontal scrolling going on. I want to reduce the amount of scrolling by creating groups when a supervisor has a lot of subordinates. When a supervisor has a lot of subordinates i want all those subordinates to be displayed vertically.

When a supervisor one above the lowest level of a department has more than two employees i want to enclose all the subordinates of that supervisor in a group. I've figured the best way of doing that would be instead of each of those subordinates being a table element, i would have all the subordinates in an unordered list with a border round them.

If i've not explained that very well then please let me know. Any halp will be greatly appreciated.

Thanks

Here is the XML

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="..\styles\orgchartsverttest.xsl" ?>
<dataroot>
<Data_For_Visio Employee_ID="3" Person_Name="Dave Smith" Reports-To="1" Position_Title="Director Of Performance" Organisation="Performance" Substantive="" Fill_Temp="">
<Data_For_Visio Employee_ID="12" Person_Name="Alex Barrow" Reports-To="3" Position_Title="Asst. Director of Performance" Organisation="Performance" Substantive="" Fill_Temp="">
<Data_For_Visio Employee_ID="21" Person_Name="John Lydon" Reports-To="12" Position_Title="Performance Manager" Organisation="Performance" Substantive="" Fill_Temp="">
<Data_For_Visio Employee_ID="990" Person_Name="Pip Brown" Reports-To="21" Position_Title="Data Manager" Organisation="Performance" Substantive="" Fill_Temp=""/>
<Data_For_Visio Employee_ID="1020" Person_Name="Jeff Buckley" Reports-To="21" Position_Title="Analyst" Organisation="Performance" Substantive="" Fill_Temp=""/>
<Data_For_Visio Employee_ID="1121" Person_Name="Keith Richards" Reports-To="21" Position_Title="Audit Manager" Organisation="Performance" Substantive="" Fill_Temp=""/>
<Data_For_Visio Employee_ID="1122" Person_Name="James Dean-Bradfield" Reports-To="21" Position_Title="Data Manager" Organisation="Performance" Substantive="" Fill_Temp=""/>
<Data_For_Visio Employee_ID="1358" Person_Name="Bez" Reports-To="21" Position_Title="Analyst" Organisation="Performance" Substantive="" Fill_Temp=""/>
</Data_For_Visio>

</Data_For_Visio>
</dataroot>

Here is the xsl file

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output method="html" encoding="iso-8859-1"/>


<xsl:template match="/">
<html>
<head>
<title></title>
<script type="text/javascript" language="JavaScript" src="..\scripts\stylemorpher.js"></script>
<link type="text/css" rel="stylesheet" href="../styles/orgcharts.css"></link>
</head>
<body>
<table cellspacing="0" cellpadding="0" class="roottable">
<tr>
<xsl:apply-templates select="dataroot"/>
</tr>
</table>
</body>
</html>
</xsl:template>



<xsl:template match="Data_For_Visio">


<xsl:for-each select="Data_For_Visio">
<xsl:choose>
<xsl:when test="count(descendant::Data_For_Visio[position()=last()&lt;2])">

<td valign="top" class="open">
<xsl:if test="parent::* and count(parent::*/*)&gt;1">
<div>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="not(preceding-sibling::*)">leftabove</xsl:when>
<xsl:otherwise>rightabove</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</div>
<div>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="not(following-sibling::*) or not(preceding-sibling::*)">nolines</xsl:when>
<xsl:otherwise>above</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</div>
</xsl:if>
<div>
<!--<xsl:if test="@Organisation">
<xsl:attribute name="class">divopen</xsl:attribute>
<xsl:attribute name="style">
<xsl:text>background: rgb(100%, </xsl:text>
<xsl:value-of select="100 - count(ancestor-or-self::*[@Organisation]) * 3" />
<xsl:text>%, </xsl:text>
<xsl:value-of select="100 - count(ancestor-or-self::*[@Organisation]) * 6" />
<xsl:text>%);</xsl:text>
</xsl:attribute>
<div class="divname"><span class="openclose" onmouseup_="var div=this.parentNode.parentNode; window.spif.styleMorpher.storeState(div); div.className=(div.className=='divclosed'?'divopen':'divclosed'); window.spif.styleMorpher.morph();"></span><xsl:value-of select="@Organisation" /></div>
</xsl:if>-->


<div class="wrapperbox">
<div class="boxc">

<div class="box">
<b><xsl:value-of select="@Person_Name" /></b>
<xsl:if test="count(.//Data_For_Visio)">
<xsl:text> (</xsl:text>
<xsl:value-of select="number(count(.//Data_For_Visio))" />
<xsl:text>)</xsl:text>
</xsl:if>
<p><xsl:value-of select="@Position_Title"/></p>
<p><xsl:value-of select="@Organisation"/></p>
<xsl:choose>
<xsl:when test="@Substantive != @Person_Name">
<b><xsl:text>Substantive: </xsl:text><xsl:value-of select="@Substantive"/></b>
</xsl:when>
<xsl:when test="@Substantive !=Null">
<b><xsl:text>Substantive: </xsl:text><xsl:value-of select="@Substantive"/></b>
</xsl:when>
</xsl:choose>
</div>
</div>
</div>
</div>

<xsl:if test="*">
<div class="linemiddle">
<div class="openclose" onmousedown_="var td=this.parentNode.parentNode.parentNode; window.spif.styleMorpher.storeState(td);td.className=(td.className=='open'?'closed':'open'); window.spif.styleMorpher.morph();">
</div>
</div>
</xsl:if>
<div class="tablewrapper">
<table cellspacing="0" cellpadding="0" align="center">
<tr>
<xsl:apply-templates select="*" />
</tr>
</table>
</div>

</td>
</xsl:when>


<xsl:when test="count(descendant::Data_For_Visio[position()=last()=&gt;2])">
<td valign="top" class="open">
<xsl:if test="parent::* and count(parent::*/*)&gt;1">
<div>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="not(preceding-sibling::*)">leftabove</xsl:when>
<xsl:otherwise>rightabove</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</div>
<div>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="not(following-sibling::*) or not(preceding-sibling::*)">nolines</xsl:when>
<xsl:otherwise>above</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</div>
</xsl:if>
<ul>
<li>
<div class="box">
<b><xsl:value-of select="@Person_Name" /></b>
<xsl:if test="count(.//Data_For_Visio)">
<xsl:text> (</xsl:text>
<xsl:value-of select="number(count(.//Data_For_Visio))" />
<xsl:text>)</xsl:text>
</xsl:if>

<p><xsl:value-of select="@Position_Title"/></p>
<p><xsl:value-of select="@Organisation"/></p>
<xsl:choose>
<xsl:when test="@Substantive != @Person_Name">
<b><xsl:text>Substantive: </xsl:text><xsl:value-of select="@Substantive"/></b>
</xsl:when>
<xsl:when test="@Substantive !=Null">
<b><xsl:text>Substantive: </xsl:text><xsl:value-of select="@Substantive"/></b>
</xsl:when>
</xsl:choose>
</div>
</li>
</ul>



<xsl:if test="*">
<div class="linemiddle">
<div class="openclose" onmousedown_="var td=this.parentNode.parentNode.parentNode; window.spif.styleMorpher.storeState(td);td.className=(td.className=='open'?'closed':'open'); window.spif.styleMorpher.morph();">
</div>
</div>
</xsl:if>
<div class="tablewrapper">
<table cellspacing="0" cellpadding="0" align="center">
<tr>
<xsl:apply-templates select="*" />
</tr>
</table>
</div>
</td>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>




but it says unexpected token >2 when i try to run the

Postnext
(Deleted User) Subject: XSLT to Html problems
Author: (Deleted User)
Date: 18 Dec 2008 05:49 AM
Hi Liam,
you have a couple of xsl:when like this

<xsl:when test="count(descendant::Data_For_Visio[position()=last()&gt;2])">

I guess you wanted something like

<xsl:when test="count(descendant::Data_For_Visio[position()=last()])&gt;2">

e.g. test the result of count() with the number 2

Alberto

Postnext
Liam BSubject: XSLT to Html problems
Author: Liam B
Date: 18 Dec 2008 06:07 AM
Thanks for the reply Alberto, but i still get exactly the same error.

Broadly speaking though i am following the right path with my XSL?

Basically want i want the XSL to do is loop through every branch of the context node , testing whether or not the last but one node has more than two children. If it does have 2 or more children then i want to execute one block of code, if it has only one child then i want to execute another block.

Postnext
(Deleted User) Subject: XSLT to Html problems
Author: (Deleted User)
Date: 18 Dec 2008 10:05 AM
Hi Liam,
the error could be cause by other occurrence of that expression, the one that end with "=&gt;2]))" in it - it should be "])&gt;=2)".

As for the logic of the test, I am not sure I understand the rationale behind it (why testing the last node only?). Anyhow, you are picking the last node in the descendant axis, and this will always pick exactly the same person (Bez) regardless of where you run the query; this because descendant::Dat_For_Visio contains all the Data_For_Visio elements in the subtree starting from the context node, and [position()=last()] will isolate the deepest one. Maybe you wanted to count the children of the current node? In that case it would be count(child::Data_For_Visio). If you need the count of the total children of the last child of the current node, it would be count(child::Data_For_Visio[position()=last()]/descendant::Data_For_Visio)

Alberto

Postnext
Liam BSubject: XSLT to Html problems
Author: Liam B
Date: 22 Dec 2008 08:46 AM
Thanks Alberto for your reply, I'm fairly new to XML (and indeed programming so please bear with me!

As regards the logioc of the test, using my example i want to count the children of John Lydon. If John Lydon has more than two employees under him then i want to display those children using an unordered list instead of table elements.


The context node will be the Boss of whichever department i'm producing a chart for. For the sake of brevity i only included a very small department in my example, but i would have to produce charts for some very large departments, as well as one for the the entire organisation.

The nodes i want to perform the test on could be at different levels in the organisation or even the same department. The one constant between them all will be that the people that they supervise will not in turn supervise anybody else. So my test needs to find the very last node, go to it's parent and then count how many children that parent node has.

Once again, thanks for your help.

Posttop
(Deleted User) Subject: XSLT to Html problems
Author: (Deleted User)
Date: 30 Dec 2008 05:20 AM
Hi Liam,
the expression count(descendant::Data_For_Visio[position()=last()]/../child::Data_For_Visio) will return the number of employees under John Lydon.

Alberto

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.