Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > problem generating html table via xslt

Reply
Thread Tools

problem generating html table via xslt

 
 
T. Sander
Guest
Posts: n/a
 
      08-20-2004
Hi !

I have the following XML-fragment :

<DL>
<DT>term 1 </DT>
<DD>def 1</DD>
<DT>term 2 </DT>
<DD>def 2</DD>
<DT>term 3 </DT>
<DD>def 3</DD>
</DL>

and want to generate a table similar to :

<html>
<body>
<table border="12">
<TR>
<TD>term 1</TD>
<TD>def 1</TD>
</TR>
<TR>
<TD>term 2</TD>
<TD>def 2</TD>
</TR>
<TR>
<TD>term 3</TD>
<TD>def 3</TD>
</TR>
</table>
</body>
</html>

So I am looking for a xsl template to generate this HTML table without
using any
<xsl:text disable-output-escaping="yes">&lt;/TD>&lt;TD></xsl:text>
or similar.


Thanks for any comments

Thilo
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      08-20-2004


T. Sander wrote:


> I have the following XML-fragment :
>
> <DL>
> <DT>term 1 </DT>
> <DD>def 1</DD>
> <DT>term 2 </DT>
> <DD>def 2</DD>
> <DT>term 3 </DT>
> <DD>def 3</DD>
> </DL>
>
> and want to generate a table similar to :
>
> <html>
> <body>
> <table border="12">
> <TR>
> <TD>term 1</TD>
> <TD>def 1</TD>
> </TR>
> <TR>
> <TD>term 2</TD>
> <TD>def 2</TD>
> </TR>
> <TR>
> <TD>term 3</TD>
> <TD>def 3</TD>
> </TR>
> </table>
> </body>
> </html>
>
> So I am looking for a xsl template to generate this HTML table


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xslutput method="html" indent="yes" encoding="UTF-8" />

<xsl:template match="/">
<html>
<head>
<title>Some definitions</title>
</head>
<body>
<xsl:apply-templates select="DL" />
</body>
</html>
</xsl:template>

<xsl:template match="DL">
<xsl:if test="DT">
<table border="12">
<tbody>
<xsl:for-each select="DT">
<tr>
<td><xsl:value-of select="." /></td>
<td><xsl:value-of select="following-sibling:D[1]" /></td>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:if>
</xsl:template>

</xsl:stylesheet>

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
William Park
Guest
Posts: n/a
 
      08-20-2004
T. Sander <(E-Mail Removed)> wrote:
> Hi !
>
> I have the following XML-fragment :
>
> <DL>
> <DT>term 1 </DT>
> <DD>def 1</DD>
> <DT>term 2 </DT>
> <DD>def 2</DD>
> <DT>term 3 </DT>
> <DD>def 3</DD>
> </DL>
>
> and want to generate a table similar to :
>
> <html>
> <body>
> <table border="12">
> <TR>
> <TD>term 1</TD>
> <TD>def 1</TD>
> </TR>
> <TR>
> <TD>term 2</TD>
> <TD>def 2</TD>
> </TR>
> <TR>
> <TD>term 3</TD>
> <TD>def 3</TD>
> </TR>
> </table>
> </body>
> </html>
>
> So I am looking for a xsl template to generate this HTML table without
> using any
> <xsl:text disable-output-escaping="yes">&lt;/TD>&lt;TD></xsl:text>
> or similar.


start () { # Usage: start tag att=value ...
case $1 in
DL) echo '<html>'; echo '<body>'; echo '<table border="12">' ;;
DT) echo '<TR>' ;;
esac
}
middle () { # Usage: middle data
case ${XML_ELEMENT_STACK[1]} in # only in <DT>..</DT> or <DD>..</DD>
DT|DD) echo "<TD>$1</TD>" ;;
esac
}
end () { # Usage: end tag
case $1 in
DL) echo '</table>'; echo '</body>'; echo '</html>' ;;
DD) echo '</TR>' ;;
esac
}

xml -s start -d middle -e end '<DL>...</DL>'

Ref:
http://freshmeat.net/projects/bashdiff/
http://home.eol.ca/~parkw/index.html#xml
help xml
--
William Park <(E-Mail Removed)>
Open Geometry Consulting, Toronto, Canada
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT to HTML table problem kanpeter XML 5 10-15-2010 02:24 PM
Convert CSV To html via XSLT Chris XML 12 06-02-2007 06:27 AM
Generating HTML from XSLT using <xsl:copy> Andy Dingley XML 3 03-27-2007 02:45 PM
Generating html out of xml using xslt Brent XML 3 03-22-2005 10:44 PM
No results from XML to HTML via XSLT? Ian Vaughan XML 4 02-04-2005 11:25 AM



Advertisments