Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] data translation => descendants appear side by side in HTML-table

From: "Oliver Kurt" <mail@---------->
To:
Date: 5/1/2002 11:45:00 AM
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


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent