Re: [xsl] XSLT and SVG

Subject: Re: [xsl] XSLT and SVG
From: "CyberSpace Industries 2000 Inc." <csi2000@xxxxxxxxxxxxxxx>
Date: Tue, 18 Jul 2006 14:21:13 -0400
I did a project once where the input was XML text and the output was to be a hiererchical family tree that was meant to show - for this particular equipment manual, what were the prerequisite manuals (parents), and what detailed manuals followed(child). Each manual was represented as a box with manual number, title and a third thing I forget. The difficulty arose when there were a variable number of parent and child manuals for each manual, and the layout was meant to be centered and symmetrical on the page. Each manual was to be connected to all its parent and child manuals. This sounds sort of what you are doing - but simpler.

I has similar difficulties and eventually wound up writing XSLT to convert every possible case into the corresponding SVG diagram (e.g. 1 parent, 2 parents, 3 parents... up to a max of 20 parents). I tried using called templates - but setting up all the parameters and then calling occupied just as much space as writing out the individual cases. In both cases I had to determine start coordinates and end coordinates for the connecting lines - and handle cross overs etc.

The project got canned before I could completely finish - but the XML to SVG was working quite well.

You seem to be calculating a position based on the position of the entry in the XML. Your problem is to use the XML to drive the connectors. I don't understand your XML - did you mean

 <Constraint_Joint
   body1_id            = "30301"
   body2_id            = "30302"
 />

I could look up what I did on this project and see what applies to your project.

Cheers..Hugh
CyberSpace Industries 2000 Inc.
XML Training and Consulting
http://www.urbanmarket.com/csi2000


----- Original Message ----- From: "Andrea Pertosa" <andrea.pertosa@xxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Tuesday, July 18, 2006 1:08 PM
Subject: [xsl] XSLT and SVG



HI all and thanks for reading!!

First I have to confess that I'm a beginner, so please be forgiving!!

I started looking at XML/XSLT some time ago, and I have to admit that
the learning curve is a bit too steep for me.

The scenario: my XML file contains bodies and joints and represents a
mechanical system.

The idea: instead of looking at the XML text in order to figure out if
the mechanism is well-formed, wouldn't it be cool to develop an XSLT
that transforms the XML file so that the mechanical system is
presented in a graphical way?

The (I think) solution: define an XSLT that creates a block diagram
made of rectangles (or circles...) for each body and a connecting line
between the two rectangles that a joint connects.

Sounds easy, no?

  Unfortunately I'm running into problems and I thought that if I
published what I have done so far, perhaps someone could tell me if
I'm on the right track or not, since I'm sure there   are many
examples of XSLT that create graphical representation of hierarchical
structure. Think of an org chart...

--------- the XML file ------------

<MultiBodySystem>
<Model>
 <Body_Rigid
    label               = "Ground"
    id                  = "30101"
 />
 <Body_Rigid
    label               = "Body 1"
    id                  = "30301"
 />
 <Body_Rigid
    label               = "Body 2"
    id                  = "30302"
 />
 <Constraint_Joint
    body1_id            = "30101"
    body2_id            = "30301"
 />
</Model>
</MultiBodySystem>

------------ the xslt file ---------------

<?xml version='1.0' encoding='utf-8' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="xml" indent="yes" version="1.0" encoding="ISO-8859-1"/>
<xsl:template match="Model">
<svg width="800" height="500">
<g id="Body_Rigid" transform="translate(0, 220)">
<xsl:for-each select="Body_Rigid">
<text x="{position()*145 + 40}" y="-70"
style="font-family: arial; text-anchor: middle;">
<xsl:value-of select="@label"/>
</text>
<text x="{position()*145 + 40}" y="-55"
style="text-anchor:end;">ID = </text>
<text x="{position()*145 + 60}" y="-55"
style="font-family: arial; text-anchor: middle;">
<xsl:value-of select="@id"/>
</text>
<rect x="{position()*145}" y="-100" height="70"
width="115" style="fill:none; stroke:black;"/>
</xsl:for-each>
</g>
</svg>
</xsl:template>
</xsl:stylesheet>


-------------------------------------------------

The output is an XML file that contains svg elements, rectangles
representing bodies.
I'm completely at loss on how to represent the connection between body
1 and body 2.

Has anyone run into a similar issue? Can anyone share their experience
or a working example where a relationship between nodes was
represented graphically using SVG?

Thanks for your help.
Andrea P.

Current Thread