[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

xml cells transformed in to a 2-d table, some table ce

Subject: xml cells transformed in to a 2-d table, some table cells missing, full table required - constant variables.
From: "Brendan Sleight" <bms@xxxxxxxxxx>
Date: Sat, 3 Jan 2009 02:00:49 +0000
 xml cells transformed in to a 2-d table
Hi All,

I am having fun with XSL. I am developing an application for traffic
signals (traffic-lights) that uses xml and the input and output. I
want to make everything based around the xml. So I decided to use
stylesheets when I need text output rather than create extra methods
on the classes. Basically I now being stubborn and am _going_ to use
stylesheets even if it drives me insane.

I have hit a snag as variables in XSL are constant. So I can not set a
flag to tell me when something has not produced a output.

I am taking a basic xml file:-
  http://www.barwap.com/files/2008/Dec/30/example-site-2.xml
Basically with lots of entries such as:-
   <intergreen>
    <from>A</from>
    <to>B</to>
    <length>7</length>
   </intergreen>
   <intergreen>
    <from>A</from>
    <to>C</to>
    <length>5</length>
   </intergreen>
   <intergreen>
    <from>B</from>
    <to>A</to>
    <length>7</length>
   </intergreen>

Each of the <intergreen> are going to be used to form a 2-d table. So
far I have got this stylesheet:-
  http://www.barwap.com/files/2009/Jan/02/site-transform-intergreens.xsl

Normally I would use python-amara -
http://uche.ogbuji.net/tech/4suite/amara/ as my XSL processor, but I
testing using xmlstarlet. http://xmlstar.sourceforge.net/, version
1.0.1-2. The command:-
xmlstarlet tr ./site-transform-intergreens.xsl ./example-site-2.xml

Gives:-
<?xml version="1.0"?>
<b>Intergreen table</b><tt><i>
 </i><i>  A</i><i>  B</i><i>  C</i><i>  D</i><i>
 A</i><b> 7 </b><b> 5 </b><i>
 B</i><b> 7 </b><i>
 C</i><b> 6 </b><i>
 D</i><b> 5 </b><b> 5 </b><b> 5 </b></tt>

Or without the <b> and <i>, A table of "from" verus "to" :-

Intergreen table
   A  B  C  D
 A 7  5
 B 7
 C 6
 D 5  5  5


However I can not find a solution where if i do not have en entry for
say, From A to D, a cell is still added to the plain text table. (Long
story but I can not use html tables.) So rather then getting a half
table I get a full populated table, the ideal answer:-

Intergreen table
    A  B  C  D
 A 0  7  5  0
 B 7  0  0  0
 C 6  0  0  0
 D 5  5  5  0

I could pre-populate the xml file with null entires, but that makes
the file on say a 32x32 table not very friendly for a human to read.

I have played around with a few options, but hit the snag that
variables in XSL are constants so flags are out of the question. Also
the stylesheet feel very poorly written by me, as I loop through all
the entries of the <intergreen> tag until I find the tag equaling row
and column, which feels very in-efficient.

So any tips on getting the stylesheet to the correct output would be
very appreciated as I have hit a bit of a brick wall and run out of
ideas. I am very new to style sheets and xml.  Can this even be done
with stylesheets ?

Best Regards,
Brendan M. Sleight

xmlstarlet tr ./processor-version.xsl ./exmaple.xml
<?xml version="1.0"?>
<html xmlns="http://www.w3.org/TR/xhtml1/strict"><head><title>XSLT
Processor Version</title>
</head><body><p>XSL version: 1.0
</p><p>Vendor: libxslt
</p><p>Vendor URL: http://xmlsoft.org/XSLT/
</p><p>Product name: [Undefined]
</p><p>Product version: [Undefined]
</p><p>Is schema-aware: [Undefined]
</p><p>Supports serialization: [Undefined]
</p><p>Supports backwards compatibility: [Undefined]
</p></body></html>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.