Hi Dominic,
OK, I see what you mean - probably the phrase that would suit the first
(formatted) example would be hierarchical. The second example, the one you
are actually having to use, is flat. The process in XSLT to process the
flat into hierarchical isn't that difficult because you have references to
the superior. Although listing it from bottom up as the hierarchy seems a
little odd (as it would enevitably lad to repetition of data)? To structure
it top (most superior) down would look something like...
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="kSubordinates" match="employee"
use="substring-after(superior/@id,'#')"/>
<!-- template to match root element -->
<xsl:template match="/*">
<!-- copy root element as is -->
<xsl:copy>
<!-- start with employees that have no superior -->
<xsl:apply-templates select="employee[not(superior)]"/>
</xsl:copy>
</xsl:template>
<xsl:template match="employee">
<!-- copy the employee element -->
<xsl:copy>
<!-- aply templates to attributes and child nodes of this employee so
they get copied -->
<xsl:apply-templates select="@* | node()"/>
<!-- create a <subordinates> element as a child of the <employee>
element -->
<subordinates>
<!-- and find all the employees whose superior is the current
employee -->
<xsl:apply-templates select="key('kSubordinates',@id)"/>
</subordinates>
</xsl:copy>
</xsl:template>
<!-- copy all elements -->
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- stop the <superior> element being copied - not needed in hierarchical
form -->
<xsl:template match="superior"/>
<!-- copy attributes and other nodes -->
<xsl:template match="@* | text() | comment() | processing-instruction()">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>
But you wouldn't need to do this in the XSLT to produce the final SVG - as
the above logic would be built into the process of generating the final SVG.
But a similar approach would be roughly the pattern the SVG building would
require.
Cheers
Marrow
"Dominic Myers" <an***********@msn.com> wrote in message
news:2u*************@uni-berlin.de...
"Marrow" <ma****@somewhere.so.fu> wrote in message
news:vo***************@newsfe1-gui.ntli.net... Hi Dominic,
Yes, it is possible - transforming XML data to SVG is...
-- snip --
Cheers for the reply Marrow,
To give an example of the "formatted" text it's be something like:
<employee id="3rd in Command">
<name>Eve Grindstaff</name>
<details>01223 603302</details>
<superior>
<employee id="2nd in Command">
<name>Lance Lenker</name>
<details>01223 608062</details>
<superior>
<employee id="1st in Command">
<name>Maricela Defore</name>
<details>01223 602362</details>
<superior/>
</employee>
</superior>
</employee>
</superior>
</employee>
Whereas the data I have is of this format:
<employee id="3rd in Command">
<name>Eve Grindstaff</name>
<details>01223 603302</details>
<superior id="#2nd in Command"/>
</employee>
<employee id="2nd in Command">
<name>Lance Lenker</name>
<details>01223 608062</details>
<superior id="#1st in Command"/>
</employee>
<employee id="1st in Command">
<name>Maricela Defore</name>
<details>01223 602362</details>
</employee>
That's what I meant by formatted XML, if you see what I mean? ;-)
The XML file is here <http://camshag.co.uk/svg/NHSTrust/NHSTrust.owl>, the
link was a bit obscure, blame it on my CSS!
I used masses of script to format the position of the employees within the
hierarchy but was wondering about the processing abilities of XSL?
Cheers, Dom