Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   problem generating html table via xslt (http://www.velocityreviews.com/forums/t167704-problem-generating-html-table-via-xslt.html)

T. Sander 08-20-2004 03:01 PM

problem generating html table via xslt
 
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

Martin Honnen 08-20-2004 03:17 PM

Re: problem generating html table via xslt
 


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
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output 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::DD[1]" /></td>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:if>
</xsl:template>

</xsl:stylesheet>

--

Martin Honnen
http://JavaScript.FAQTs.com/

William Park 08-20-2004 05:07 PM

Re: problem generating html table via xslt
 
T. Sander <roetz7@unicum.de> 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 <opengeometry@yahoo.ca>
Open Geometry Consulting, Toronto, Canada


All times are GMT. The time now is 04:29 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57