modulo

G

graf.laszlo

Hi all,

I have an XML structure wich looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<a>
<b1 id="1">
<c1>C11</c1>
<c2>C12</c2>
...
</b1>
<b1 id="2">
<c1>C21</c1>
<c2>C22</c2>
...
</b1>
<b1 id="3">
<c1>C31</c1>
<c2>C32</c2>
...
</b1>
...
<b1 id="m">
<c1>C(m)1</c1>
<c2>C(m)2</c2>
...
</b1>
</a>
where the number of 'b' tags is greater than 3 and the number of 'c'
tags is greater than 2.
How can I transform the XML data using XSLT to get the following HTML
table structure?

<table>
<tr>
<td>
<table>
<tr>
<th>b1 (id=1)</th>
<td>c1 : C11</td>
<td>c2 : C12</td>
...
</tr>
</table>
</td>
<td>
<table>
<tr>
<th>b1 (id=2)</th>
<td>c1 : C21</td>
<td>c2 : C22</td>
...
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<th>b1 (id=3)</th>
<td>c1 : C31</td>
<td>c2 : C32</td>
...
</tr>
</table>
</td>
<td>
<table>
<tr>
<th>b1 (id=4)</th>
<td>c1 : C41</td>
<td>c2 : C42</td>
...
</tr>
</table>
</td>
</tr>
...
</table>

Thank you,
Laci
 
G

George Bina

Hi Laci,

I cannot see any difficulty here, something as simple as the stylesheet
below will get you the desired output:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput indent="yes"/>

<xsl:template match="a">
<table>
<tr><xsl:apply-templates/></tr>
</table>
</xsl:template>
<xsl:template match="b1">
<td>
<table>
<tr>
<th><xsl:value-of select="name()"/> (id=<xsl:value-of
select="@id"/>)</th>
<xsl:apply-templates/>
</tr>
</table>
</td>
</xsl:template>
<xsl:template match="c1|c2">
<td><xsl:value-of select="name()"/> : <xsl:value-of
select="."/></td>
</xsl:template>
</xsl:stylesheet>

Best Regards,
George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top