Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Tip: Convert from HTML to XML with HTML Tidy

By Benoit Marchal
2003-12-16


Listing 4. cleanup.xsl

<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:gl="http://ananas.org/2003/tips/gallery"
xmlns:html="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="html">

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

<xsl:template match="html:html">
<xsl:variable name="date"
select="html:body/html:table/html:tr/html:td[2]
/html:font/html:br[3]
/preceding-sibling::text()[1]"/>
<gl:gallery>
<gl:title>
<xsl:value-of select="html:head/html:title"/>
</gl:title>
<xsl:for-each select="html:body/html:center/html:table
/html:tr/html:td">
<xsl:variable name="title"
select="html:font/html:br[3]
/preceding-sibling::text()[1]"/>
<xsl:variable name="image"
select="html:font/html:br[1]
/preceding-sibling::text()[1]"/>
<xsl:variable name="description"
select="html:font/html:br[2]
/preceding-sibling::text()[1]"/>
<gl:photo>
<gl:title><xsl:value-of
select="normalize-space($title)"/></gl:title>
<gl:date><xsl:value-of
select="normalize-space($date)"/></gl:date>
<gl:image><xsl:value-of
select="normalize-space($image)"/></gl:image>
<gl:description><xsl:value-of
select="normalize-space($description)"/></gl:description>
</gl:photo>
</xsl:for-each>
</gl:gallery>
</xsl:template>

</xsl:stylesheet>


Tutorial Pages:
» Preserve Legacy Web Sites With This Handy Utility
» Tool Of The Trade
» Listing 1. index.html (an excerpt)
» Tidying Up
» Listing 2. index.xml (an excerpt)
» Further Processing
» Listing 3. index-transform.xml (an excerpt)
» Listing 4. cleanup.xsl
» Conclusion


First published by IBM developerWorks


Related Tutorials:
» Starting with XML
» Performing Client-Side XSL Transformations
» Create a Google Sitemap for your Web Site
» XML and Scripting Languages
» Parsing Comma-Separated Values
» XML Security Suite: Increasing the Security of E-Business

Ask A Question
characters left.