xsl-list
[Top] [All Lists]

Re: Newbie - XML and XSLT samples to produce XHTML Files please

2005-01-25 12:41:44
Tempore 18:55:44, die 01/25/2005 AD, hinc in xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com scripsit Julian Voelcker <asp(_at_)tvw(_dot_)net>:

I now want to try to build it up so that the menus (bulleted lists) and
main page content are extracted from an XML file.

Do any of you have a set of XML/XSLT files that you could email me to
show examples of a reasonably complex site designs that I could look
at?
The following example is rather trivial, but once you fully understand how it works, you can handle the most complex XSLT.

consider this XML:

<?xml version="1.0" encoding="UTF-8"?>
<site title="New Company Website Design">
        <nav id="main">
                <link>About <anchor>Company</anchor></link>
                <link>Housing <anchor>opportunities</anchor></link>
                <link><anchor>Regeneration</anchor></link>
        </nav>
        <par>some text</par>
</site>


and this xsl:

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

<!-- output method is 'xml': 'html' will not produce valid (x)html -->
<xsl:output method="xml" version="1.0" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"; indent="yes" />

<xsl:template match="site">
<!-- I moved the xhtml namspace declaration to the xsl:stylesheet element -->
        <html lang="eng" xml:lang="eng">
                <head>
                        <title><xsl:value-of select="@title"/></title>
                        <link rel="stylesheet" type="text/css" 
href="/STYLES/basic.css"/>
                </head>
                <body>
                        <xsl:apply-templates/>
                </body>
        </html>
</xsl:template>

<xsl:template match="nav">
        <div id="{(_at_)id}menu">
                <ul>
                        <xsl:apply-templates/>
                </ul>
        </div>
</xsl:template>

<xsl:template match="link">
        <li id="menu{position()}">
                <a href="#{anchor}"><xsl:apply-templates/></a>
        </li>
</xsl:template>

<xsl:template match="par">
        <p>
                <xsl:apply-templates/>
        </p>
</xsl:template>

<!-- no template is defined for the 'anchor' elements; the deafult is text nodes only-->
</xsl:stylesheet>

It will produce this xhtml output:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml"; lang="eng" xml:lang="eng">
        <head>
                <title>New Company Website Design</title>
                <link rel="stylesheet" type="text/css" 
href="/STYLES/basic.css"/>
        </head>
        <body>
                <div id="mainmenu">
                        <ul>
                                <li id="menu1">
                                        <a href="#Company">About Company</a>
                                </li>
                                <li id="menu2">
                                        <a href="#opportunities">Housing 
opportunities</a>
                                </li>
                                <li id="menu3">
                                        <a href="#Regeneration">Regeneration</a>
                                </li>
                        </ul>
                </div>
                <p>some text</p>
        </body>
</html>


regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
"Φιλήκοον ειναι μαλλον η φιλόλαλον" - Κλεόβουλος

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--