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
David CarrigerSubject: XSLT: Possible To Add X,Y Space If Additional XML Data Exists?
Author: David Carriger
Date: 22 Jul 2004 10:15 AM
Back, again!

My query this time: In my XSLT, I am requesting data from my XML source files if it exists within specific elements and stating that if it does, stream and transform this data into an SVG at these given X,Y coordinates in my viewbox. To date, I have found nothing in either XSLT or SVG specifications that would allow for a flexible flow of data...all data seems to be etched in stone based on these X,Y coordinates. Am I wrong on this matter? Are X,Y coordinates more flexible than I have discovered? Please tell me "Yes"!

In my particular situation, I have flowchart logic-test's (my source XML files) which may contain any number of <step><para><pcnarr>'s (<pcnarr> being the only element which may contain PCDATA). These I have accommodated to flow into my XSLT transformed SVG as such:

[code]
SOURCE XSLT:

<xsl:template match="logic-test">
<svg width="100%" height="100%">
<g>
<xsl:for-each select="descendant-or-self::step">
<xsl:if test="position()=1 and not(para/null)">
<text x="10" y="75" style="text-anchor: start; font-size: 8pt;">
<xsl:number format="1. " level="single"/>
<xsl:value-of select="para/pcnarr"/>
</text>
</xsl:if>

<xsl:if test="position()=2 and not(para/null)">
<text x="10" y="90" style="text-anchor: start; font-size: 8pt;">
<xsl:number format="1. " level="single"/>
<xsl:value-of select="para/pcnarr"/>
</text>
</xsl:if>

<xsl:if test="position()=3 and not(para/null)">
<text x="10" y="105" style="text-anchor: start; font-size: 8pt;">
<xsl:number format="1. " level="single"/>
<xsl:value-of select="para/pcnarr"/>
</text>
</xsl:if>

<xsl:if test="position()=4 and not(para/null)">
<text x="10" y="105" style="text-anchor: start; font-size: 8pt;">
<xsl:number format="1. " level="single"/>
<xsl:value-of select="para/pcnarr"/>
</text>
</xsl:if>
<!-- A TABLE EXISTS HERE WITH 4 ROWS -->
<xsl:if test="position()=5 and not(para/null)">
<text x="10" y="105" style="text-anchor: start; font-size: 8pt;">
<xsl:number format="1. " level="single"/>
<xsl:value-of select="para/pcnarr"/>
</text>
</xsl:if>
<!-- A TABLE EXISTS HERE WITH 8 ROWS -->
</xsl:for-each>
</g>
<xsl:apply-templates/>
</svg>
</xsl:template>
[/code]

My problem exists in that at any given time, these <step><para><pcnarr>'s may also include <table>'s between them, which in themselves may also contain any number of <row><entry><pcnarr>'s. Given the following <table>:

[code]
SOURCE XML:

<table frame="none" id=" ">
<title><null/></title>
<tgroup cols="2">
<colspec align="right" colwidth="1.25in"/>
<colspec align="left" colwidth="1.00in"/>
<tbody>
<row id="T00002-TS-11-5820-890-30-327">
<entry align="right"><pcnarr>MODE:</pcnarr></entry>
<entry align="left"><pcnarr>MTRS</pcnarr></entry>
</row>
<row id="T00002-TS-11-5820-890-30-328">
<entry align="right"><pcnarr>SELECT:</pcnarr></entry>
<entry align="left"><pcnarr>DMM</pcnarr></entry>
</row>
<row id="T00002-TS-11-5820-890-30-329">
<entry align="right"><pcnarr>FUNCTION:</pcnarr></entry>
<entry align="left"><pcnarr>DCV</pcnarr></entry>
</row>
<row id="T00002-TS-11-5820-890-30-330">
<entry align="right"><pcnarr>RANGE:</pcnarr></entry>
<entry align="left"><pcnarr>200 V</pcnarr></entry>
</row>
</tbody>
</tgroup>
</table>
[/code]

...and that this <table> falls after step #4 (having 4 rows) and that another similar <table> exists after step #5, is it at all possible to create some sort of a formula/counter/whatever which will be able to read the XML source file; determine that these <table>'s exist; and not only stream this tabulated data into the SVG, but provide the additional horizontal "Y" space necessary to accomodate however many <row><pcnarr>'s exist?

Or is this all just pushing the XSLT/SVG specifications too far? Perhaps possible with the assistance of JavaScript? If so...how?

Any help on this issue would be geatly appreciated.

David

Postnext
Ivan PedruzziSubject: XSLT: Possible To Add X,Y Space If Additional XML Data Exists?
Author: Ivan Pedruzzi
Date: 23 Jul 2004 10:02 PM
Hi David,

I hope you already solved your problem, but if you didn't the example
below may give you some inspiriting ideas.

The following XSLT fetch all 'table' elements then print the
tgroup/tbody/row/entry/pcnarr value in sequence incrementing the Y coordinate.
based on the node position.

<?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:template match="/">
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">
<g>
<xsl:apply-templates/>
</g>
</svg>
</xsl:template>

<xsl:template match="text()"/>

<xsl:template match="table">
<xsl:variable name="y-offset" select="position()*20"/>
<xsl:for-each select="tgroup/tbody/row">
<text x="10" y="{20 * position() + $y-offset}" style="text-anchor: start; font-size: 8pt;">
<xsl:value-of select="entry/pcnarr"/>
</text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Posttop
Lee HumphriesSubject: XSLT: Possible To Add X,Y Space If Additional XML Data Exists?
Author: Lee Humphries
Date: 04 Aug 2004 10:23 PM
Hi David,

>My query this time: In my XSLT, I am requesting data
>from my XML source files if it exists within specific
>elements and stating that if it does, stream and transform
>this data into an SVG at these given X,Y coordinates in my
>viewbox. To date, I have found nothing in either XSLT or SVG
>specifications that would allow for a flexible flow of
>data...all data seems to be etched in stone based on these
>X,Y coordinates. Am I wrong on this matter?
Yep - More later.

>Are X,Y coordinates more flexible than
>I have discovered? Please tell me "Yes"!
Alright then - "Yes"!

>is it at all possible to create some sort of a
>formula/counter/whatever which will be able to read the XML
>source file; determine that these <table>'s exist;
>and not only stream this tabulated data into the SVG,
>but provide the additional horizontal "Y" space necessary
>to accomodate however many <row><pcnarr>'s exist?
Yes - sorry "Yes"!

>Or is this all just pushing the XSLT/SVG specifications
>too far?
Trust me - you're not even close.

The other reply you've got shows an answer.
But there are an enormous variety of approaches.
Using xsl:variable and the XPath count() function are really good places to start.
Also recursive templates are extremely important in solving these sorts of problems especially when the source starts getting complicated.
In your case though just using templates more would be a good start.

 
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.