473,385 Members | 1,372 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Can XSL do this, and if so... how?

Hi there,

this may be a bit out there but I have a XML data file of a hierarchy and
I'd like to output the file using XSL, the thing is I don't know if it works
like that? I've now got an got a SVG file
http://camshag.co.uk/svg/NHSTrust/index.html which reads the data and
outputs the hierarchy as an image using a shed-load of ecmascript, this
works but I'm wondering if there is a simpler way of doing it? I came across
a script in the XML Journal which did it, but only with preformatted XML,
the XML I have isn't formatted :-(.

Please do check the link above as, apart from anything, I'd welcome
constructive criticism on it.

Thanks in advance,

Dominic
Jul 20 '05 #1
3 2338
Hi Dominic,

Yes, it is possible - transforming XML data to SVG is, in essence, 'just' an
XML-to-XML transformation in XSLT. ('just' being quantitive based on your
previous XSLT experience ;)). How - would be difficult to answer without
seeing the XML data (which doesn't appear to be available anywhere on your
web site).

I would imagine the most likely difficulties you would encounter in trying
to do this in XSLT would be:-
* calculating the overall size (height and width) or the viewport/whatever -
because this will need to be based in some way on the data;
* determining how to draw the tree lines (the complexity of this may depend
a lot on the structure of your initial XML data).

A couple of examples of XML-to-SVG using XSLT (not related to your
requirements - but may be of some use):-

http://www.topxml.com/code/default.a...l=svg&sw=categ

http://www.topxml.com/code/default.a...l=svg&sw=categ

http://www.topxml.com/code/default.a...l=svg&sw=categ
I came across
a script in the XML Journal which did it, but only with preformatted XML,
the XML I have isn't formatted :-(.
"Preformatted XML"? "XML isn't formatted"? What do you mean by
"formatted"?

Cheers
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator
"Dominic Myers" <an***********@msn.com> wrote in message
news:2u*************@uni-berlin.de... Hi there,

this may be a bit out there but I have a XML data file of a hierarchy and
I'd like to output the file using XSL, the thing is I don't know if it works like that? I've now got an got a SVG file
http://camshag.co.uk/svg/NHSTrust/index.html which reads the data and
outputs the hierarchy as an image using a shed-load of ecmascript, this
works but I'm wondering if there is a simpler way of doing it? I came across a script in the XML Journal which did it, but only with preformatted XML,
the XML I have isn't formatted :-(.

Please do check the link above as, apart from anything, I'd welcome
constructive criticism on it.

Thanks in advance,

Dominic

Jul 20 '05 #2
"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
Jul 20 '05 #3
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

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: James | last post by:
I have a from with 2 fields: Company & Name Depening which is completed, one of the following queries will be run: if($Company){ $query = "Select C* From tblsample Where ID = $Company...
5
by: Scott D | last post by:
I am trying to check and see if a field is posted or not, if not posted then assign $location which is a session variable to $location_other. If it is posted then just assign it to...
2
by: Nick | last post by:
Can someone please tell me how to access elements from a multiple selection list? From what ive read on other posts, this is correct. I keep getting an "Undefined variable" error though... Form...
2
by: Alexander Ross | last post by:
I have a variable ($x) that can have 50 different (string) values. I want to check for 7 of those values and do something based on it ... as I see it I have 2 options: 1) if (($x=="one") ||...
0
by: Dan Foley | last post by:
This script runs fine, but I'd like to know why it's so slow.. Thanks for any help out there on how i can make it faster (it might take up to 5 min to write these 3 export files whith 15 records...
5
by: Lee Redeem | last post by:
Hi there I've created abd uploaded this basic PHP script: <html> <head> <title>PHP Test</title> </head> <body> <H1 align="center">
5
by: christopher vogt | last post by:
Hi, i'm wondering if there is something like $this-> to call a method inside another method of the same class without using the classname in front. I actually use class TEST { function...
6
by: Phil Powell | last post by:
Ok guys, here we go again! SELECT s.nnet_produkt_storrelse_navn FROM nnet_produkt_storrelse s, nnet_produkt_varegruppe v, nnet_storrelse_varegruppe_assoc sv, nnet_produkt p WHERE...
1
by: Michel | last post by:
a site like this http://www.dvdzone2.com/dvd Can you make it in PHP and MySQL within 6 weeks? If so, send me your price 2 a r a (at) p a n d o r a . b e
11
by: Maciej Nadolski | last post by:
Hi! I can`t understand what php wants from me:( So: Cannot send session cache limiter - headers already sent (output started at /home/krecik/public_html/silnik.php:208) in...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.