Nesting

Discussion in 'XML' started by jjjlda, May 3, 2004.

  1. jjjlda

    jjjlda Guest

    I am a bit of a novice and am running into trouble when trying to
    create the xsl file to format my xml document. My xml document is of
    the form:

    <articles>
    <publication>
    <title>Title</title>
    <filename>/dir/filename.txt</filename>
    <authors>Author</authors>
    <source>Source</source><date>Date</date>
    </publication>
    <articles>

    I want the data to be formatted as follows at the end:

    <table>
    <tr><td><a href="/dir/filename.txt">Title</a></td></tr>
    <tr><td>Author</td></tr>
    <tr><td>Source</td></tr>
    <tr><td>Date</td></tr>
    </table>

    I have come up with the following xsl file, but I cannot get the href
    to work because it requires me to nest tags. I realzie the formatting
    is a bit different, but this should be irrelevant.

    <?xml version="1.0" encoding="iso-8859-1" ?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:template match="articles">
    <html><head><title><xsl:text>Reference</xsl:text></title></head>
    <body>
    <h1><xsl:text>Articles</xsl:text></h1>
    <table border="0" cellpadding="2" cellspacing="2">
    <xsl:apply-templates/>
    </table>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="publication">
    <tr>
    <td><b><a href="child::filename"><xsl:value-of
    select="title"/></a></b></td>
    </tr>
    <tr>
    <td><xsl:value-of select="authors"/></td>
    </tr>
    <tr>
    <td><xsl:value-of select="source"/><xsl:text>,
    </xsl:text><xsl:value-of select="date"/></td>
    </tr>
    <tr>
    <td colspan="3"><br></br></td>
    </tr>
    </xsl:template>

    </xsl:stylesheet>

    Can someone please help a novice out?

    Thanks!
     
    jjjlda, May 3, 2004
    #1
    1. Advertising

  2. > I have come up with the following xsl file, but I cannot get the href
    > to work because it requires me to nest tags. I realzie the formatting
    > is a bit different, but this should be irrelevant.
    >

    To get the href tag working you want to to something like this in your
    stylesheet:

    <a>
    <xsl:attribute name="href"><xsl:value-of
    select="filename"/></xsl:attribute>
    <xsl:value-of select="title"/>
    </a>

    Hope that helps.

    --
    Toivo Lainevool
    http://www.XMLPatterns.com - Develop effective DTDs and XML Schema
    documents for your XML using structural design patterns.
     
    Toivo Lainevool, May 4, 2004
    #2
    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. DeadlyTedly
    Replies:
    2
    Views:
    2,583
    Ted Bradley
    Oct 16, 2003
  2. Edward

    Nesting Datagrids

    Edward, Nov 11, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    2,369
    Guest
    Nov 11, 2003
  3. John

    Nesting Datagrids

    John, Nov 11, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    362
  4. Bijoy Naick

    Three Level Repeater Nesting - HELP!!!

    Bijoy Naick, Aug 10, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,894
    Bijoy Naick
    Aug 10, 2004
  5. Trans
    Replies:
    10
    Views:
    326
    Sean O'Halpin
    Sep 16, 2005
Loading...

Share This Page