Re: [xsl] basic xml help

Subject: Re: [xsl] basic xml help
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Mon, 08 Aug 2005 16:47:26 +0200
Hi,

Tempore 16:08:22, die 08/08/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Steven Hughes <shughes@xxxxxxxxxxxxxxxxx>:

I am trying to convert a simple html page with css to an xml page with xsl.

The page is very simple, it just has a few images and some anchor tags and about
6 different sections that the anchors refer to.  It seems so simple that I
should be able to figure it out, alas I need some help.

I did not really understand the goals you are trying to achieve. Why don't you stick with XHTML? That ought to be much more usable than this home-made XML document. It's bad practice to keep inventing new element names (a1,b1,...) in your XML. But if you insist on using your own XML, try to separate content, style and accessibility

All those headerlinks and '<link><a href="#top" >back to top</a></link>' belong in the XSL.

Here you have a basic stylesheet that tries to make something useful out of the provided XML

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="xml" indent="yes"/>

<xsl:template match="acadguide">
<html>
<head>
<title><xsl:value-of select="title"/></title>
</head>
<body>
	<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="figures/*">
<a href="{full_src}" title="Click to enlarge this image">
	<img src="{thumb_src}" title="{caption}"/>
</a>
</xsl:template>

<xsl:template match="link[href]">
<a href="{href}">
	<xsl:value-of select="label"/>
</a>
</xsl:template>

<xsl:template match="a">
<xsl:copy-of select="."/>
</xsl:template>

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

<xsl:template match="title">
<h1><xsl:apply-templates/></h1>
</xsl:template>

<xsl:template match="section/title">
<h1><a>
	<xsl:attribute name="name">
		<xsl:text>section_</xsl:text><xsl:number count="section" format="001"/>
	</xsl:attribute>
	<xsl:apply-templates/>
</a></h1>
</xsl:template>

<xsl:template match="subtitle">
<h2><xsl:apply-templates/></h2>
</xsl:template>

</xsl:stylesheet>

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Vincit omnia simplicitas
Keep it simple

Current Thread