Nesting

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jjjlda

    #1

    Nesting

    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>Sourc e</source><date>Da te</date>
    </publication>
    <articles>

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

    <table>
    <tr><td><a href="/dir/filename.txt">T itle</a></td></tr>
    <tr><td>Autho r</td></tr>
    <tr><td>Sourc e</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:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:template match="articles ">
    <html><head><ti tle><xsl:text>R eference</xsl:text></title></head>
    <body>
    <h1><xsl:text>A rticles</xsl:text></h1>
    <table border="0" cellpadding="2" cellspacing="2" >
    <xsl:apply-templates/>
    </table>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="publicat ion">
    <tr>
    <td><b><a href="child::fi lename"><xsl:va lue-of
    select="title"/></a></b></td>
    </tr>
    <tr>
    <td><xsl:valu e-of select="authors "/></td>
    </tr>
    <tr>
    <td><xsl:valu e-of select="source"/><xsl:text>,
    </xsl:text><xsl:v alue-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!
  • Toivo Lainevool

    #2
    Re: Nesting

    > I have come up with the following xsl file, but I cannot get the href[color=blue]
    > to work because it requires me to nest tags. I realzie the formatting
    > is a bit different, but this should be irrelevant.
    >[/color]
    To get the href tag working you want to to something like this in your
    stylesheet:

    <a>
    <xsl:attribut e name="href"><xs l:value-of
    select="filenam e"/></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.

    Comment

    Working...