Re: [xsl] Transforming XHTML to XHTML using XSLT

Subject: Re: [xsl] Transforming XHTML to XHTML using XSLT
From: "Joerg Heinicke" <joerg.heinicke@xxxxxx>
Date: Sun, 31 Mar 2002 12:16:57 +0200
Hello Anand,

I wouldn't make a difference between normal XML and XHTML. XHTML is XML too,
only with a special DTD. So you can easily use all documentations for XSLT.

Now your example: The important is always the XML (or the XHTML) which is
transformed. In the stylesheet there is only written should be done with the
nodes found in the XML. Normal processing is "in document order", with XSLT
you can change the general processing.

The only problem a beginner can have with your file is the namespace, you
set your XHTML-elements in: <html xmlns="http://www.w3.org/1999/xhtml";>.
This means, every element which is a descendant of html (without a
namespace-prefix and setting a new namespace) and html itself are in this
XHTML namespace. This must be known in the XSLT too and you have to set the
same namespace.

The simplest stylesheet for extracting title and paragraphs:

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

    <xsl:output method="text"/>

    <xsl:template match="title">
        <xsl:text>title: </xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>&#10;</xsl:text>
    </xsl:template>

    <xsl:template match="p">
        <xsl:text>paragraph "</xsl:text>
        <xsl:value-of select="@name"/>
        <xsl:text>": </xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>&#10;</xsl:text>
    </xsl:template
</xsl:stylesheet>

Hope this helps,

Joerg

> I would like to use XSLT to transform one XHTML document to another XHTML
> document.  I have come across numerous articles that state that this is
> possible, but I have yet to see any working examples.
>
> Here is a simple XHTML document:
>
> --------------- begin XHTML document -----------------------------
>
> <!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";>
> <head>
> <title> XHTML sample </title>
> </head>
>
> <body>
>
> <p name="who">Anand</p>
> <p name="job">Web Developer</p>
> <p name="area">California</p>
>
> </body>
> </html>
>
> --------------- end XHTML document -----------------------------
>
> My question is two fold: 1) What would a simple XSL style sheet to extract
> the title and various <p> tags look like? 2) Any body know of any good
books
> or website that have specific examples of XHTML being transformed with
XSLT?
>
> Thanks,
>
> Anand


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread