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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> - XSLT slicing and orphan contro... (1)
-> + How to delete CDATA using XSL... (15)
-> + Remove only root namespace, bu... (3)
-> + String Parsing (3)
-> + Calling Java method from XSL (3)
-> + populate xsl file from xsd fil... (5)
-> + formating a number like #'###.... (3)
-> + Help with grouping children, f... (20)
-> + Need help for newbie! (3)
-> + xpath in string format (2)
-> + How to populate elements at ra... (4)
-> + Changing Date format in XLST (2)
-> + Please help....How could I rem... (2)
-> + Counting children and grandchi... (7)
-> + Nested tags (4)
-> + Problem with XSLT on a Soap En... (2)
-> + Problem with XSLT on a Soap En... (5)
-> + Comparison between XSLT proces... (2)
-> + Printing non-existing value (9)
-> + big input file for XSLT (14)
-> + Is there any way to store xpat... (2)
-> + Encoding special charecters (2)
-> + Sorting (3)
-> + XML to PDF using XSL:FO (3)
-> + How to find the line number in... (2)
-> + How to set a marker for paper ... (2)
-> + Not equality Function (2)
-> + Counting Elements (4)
-> + Looking for help or code samp... (2)
-> + Help needed in pattern matchin... (2)
-> + Repeaters and Ifs (2)
-> + select adjacent nodes in xpath... (3)
-> + Stripping of Empty Target Elem... (2)
-> + auto-generate Edifact Intercha... (5)
-> + Qname Error in xsl:element (2)
-> + [Newbie] Type conversion and f... (2)
-> + Do ...when (2)
-> + Using Key (3)
-> + sorting elements in option (2)
-> + NaN(not available) value repla... (3)
-> + infinite loop error when tryin... (9)
-> + Escape a character in the stri... (3)
-> + find sum of 2 elements in xml (2)
-> + placing a ' * ' by reading the... (3)
-> + Problem in dispaying Current D... (4)
-> + Merging Table Cells in XSLT re... (3)
-> + xsl fo block-container and foo... (2)
-> + Is is possible to create a .CO... (2)
-> + printing a parent node value i... (2)
-> + Mime header info setup? (3)
-> + Calculating a Date based on 4 ... (3)
-> + XSLT formatting number issue (10)
-> + map repeating elements separat... (3)
-> + Combining XML elements based o... (3)
-> + Convert XML to UTF-8 (8)
-> + XSLT and MS Access 2007 Optio... (5)
-> - WORDML list to XML list (1)
-> + [Newbie] Using lookups in XSLT... (3)
-> + Comparing 2 passed Date Values (2)
-> + ERROR XQueryMediator Error du... (2)
-> + XML / XSLT... Unordered lists ... (2)
-> + Specify image path in XSL (2)
-> + Variable within a variable (3)
-> + How to call jfreechart method ... (8)
-> + leading and trailing white spa... (2)
-> - XSLT to Html problems (6)
-> ->XSLT to Html problems
-> ->XSLT to Html problems
-> ->XSLT to Html problems
-> ->XSLT to Html problems
-> ->XSLT to Html problems
-> + How to set classpath, when i n... (3)
-> + Error in using functions (4)
-> + To find the occurence of a cha... (3)
-> + PLMXML to XML (4)
-> + Transform multiple node values... (2)
-> + I am in need of svg example(s)... (13)
-> + count in XSLT, Need Help Pleas... (2)
-> + Help with XML.Report and Gener... (2)
-> + for each loop and variable (5)
-> + Problem with selecting nodes f... (3)
-> + Getting "Expected elemenmt mis... (2)
-> + Help with attached XML mapping... (8)
-> + xml:space="Preserve" and Embed... (2)
-> + XSLT and Multiple Strings (2)
-> + XSL Date format (2)
-> + check element contents against... (3)
-> + XML to XML Namespace conversio... (2)
-> - Supressing subgroup headers in... (1)
-> - HTML to fo conversion using XS... (1)
-> + No Topic (2)
-> + parsing xml using xslt HELP (2)
-> + Multiple Page Headers (2)
-> + PLM Xml To Generic XML (3)
-> + XSLT/XPath Help (2)
-> + XSL Space Issue (2)
-> + wanting help with xslt custom ... (3)
-> - Update input xml content with ... (1)
-> + Error: namespace prefix xsl on... (3)
-> + Error in my xsl:if test... (2)
-> - calling javascript from XSLT (1)
-> + Error when trying to a call a ... (2)
-> - HTTP POST from XSLT (1)
-> + passing xml document as input ... (2)
-> + XSLT for WORDML table to CALS ... (2)
-- Previous [361-380] [381-400] [401-420] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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

   
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.