problem generating html table via xslt

Discussion in 'XML' started by T. Sander, Aug 20, 2004.

  1. T. Sander

    T. Sander Guest

    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
    T. Sander, Aug 20, 2004
    #1
    1. Advertising

  2. 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:eek:utput 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/
    Martin Honnen, Aug 20, 2004
    #2
    1. Advertising

  3. T. Sander

    William Park Guest

    T. Sander <> 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 <>
    Open Geometry Consulting, Toronto, Canada
    William Park, Aug 20, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ian Vaughan
    Replies:
    4
    Views:
    488
    Ian Vaughan
    Feb 4, 2005
  2. Brent
    Replies:
    3
    Views:
    765
    Peter Flynn
    Mar 22, 2005
  3. Andy Dingley
    Replies:
    3
    Views:
    541
    Martin Honnen
    Mar 27, 2007
  4. Chris
    Replies:
    12
    Views:
    2,591
    Dimitre Novatchev
    Jun 2, 2007
  5. kanpeter

    XSLT to HTML table problem

    kanpeter, Oct 12, 2010, in forum: XML
    Replies:
    5
    Views:
    1,723
    Martin Honnen
    Oct 15, 2010
Loading...

Share This Page