|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Newbie - XML and XSLT samples to produce XHTML Fil
Tempore 18:55:44, die 01/25/2005 AD, hinc in
xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Julian Voelcker <asp@xxxxxxx>:
The following example is rather trivial, but once you fully understand how it works, you can handle the most complex XSLT.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. 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="{@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) "CB&CB9CB;CB.CB:CB?CB?CB= CB5CB9CB=CB1CB9 CB<CB1CB;CB;CB?CB= CB7 Cb CB9CB;CECB;CB1CB;CB?CB=" - CE!CB;CB5CECB2CB?Cb&CB;CB?Cb
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








