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

data translation => descendants appear side by side in

Subject: data translation => descendants appear side by side in HTML-table
From: "Oliver Kurt" <mail@xxxxxxxxxx>
Date: Wed, 1 May 2002 21:52:01 +0200
xslt for data translation
Hi,

I want to transform XML into HTML, but my basic problem is that I've 2
'base' elements. The descendants(!) of these base elements should appear in
the HTML side by side. So the children of the base elements have
descriptions and also children with descriptions. Independent of the type of
these elements (could type_a or type_b) the descriptions should apear side
by side in a row.

BTW: this problem would be very easy to solve, if type_a elements had no
type_b children. But thereby the structure of the first "base" element is
different to the second 'base' element. This is my problem!

To make clear what I mean, I inserted a DTD, a example XML and the resulting
HTML:

<!ELEMENT root (base+)>
<!ELEMENT base (type_a+)>
<!ELEMENT type_a (description, type_b*)>
<!ELEMENT type_b (description)>
<!ELEMENT description (#PCDATA)>

for example something like that:

<root>
 <base>
  <type_a>
   <description>some_desc1</description>
  </type_a>
  <type_a>
   <description>some_desc2</description>
   <type_b>
    <description>some_add_desc3</description>
   </type_b>
   <type_b>
    <description>some_add_desc4</description>
   </type_b>
  </type_a>
 </base>
 <base>
  <type_a>
   <description>some_desc1</description>
   <type_b>
    <description>some_add_desc2</description>
   </type_b>
  </type_a>
  <type_a>
   <description>some_desc3</description>
  </type_a>
  <type_a>
   <description>some_desc4</description>
   <type_b>
    <description>some_add_desc5</description>
   </type_b>
  </type_a>
 </base>
</root>

should be transformed into:

<table>
    <tr>
        <td>some_desc1</td>
        <td>some_desc1</td>
    </tr>
    <tr>
        <td>some_desc2</td>
        <td>some_add_desc2</td>
    </tr>
    <tr>
        <td>some_add_desc3</td>
        <td>some_desc3</td>
    </tr>
    <tr>
        <td>some_add_desc4</td>
        <td>some_desc4</td>
    </tr>
    <tr>
        <td></td>
        <td>some_add_desc5</td>
    </tr>
</table>


Now I wrote a stylesheet, which looks like this:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="root">
 <HTML>
 <BODY>
 <table border="1" cellpadding="5" cellspacing="0">
  <xsl:apply-templates select="base[position()=1]/type_a"/>
 </table>
 </BODY>
 </HTML>
</xsl:template>
<xsl:template match="type_a">
 <xsl:variable name="pos" select="position()"/>
 <tr>
 <td>
  <xsl:value-of select="description"/>
 </td>
 <td>
  <xsl:value-of
select="/root/base[position()=2]/type_a[position()=$pos]/description"/>
 </td>
 </tr>
 <xsl:apply-templates select="type_b"/>
</xsl:template>
 <xsl:template match="type_b">
 <tr>
 <td>
  <xsl:value-of select="description"/>
 </td>
 <td>
  <!-- here I've not even an idea -->
  <!-- <xsl:value-of
select="/root/base[position()=2]/type_a[position()=???]/type_b[position()=??
]/description"/> -->
 </td>
 </tr>
</xsl:template>
</xsl:stylesheet>

But that doesn't work at all. Maybe that is a totaly wrong approach, but
I've no better idea.

Any ideas are very welcome :-)

Best regards
Oliver Kurt


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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-2013 All Rights Reserved.