[xsl] Reprocessing XHTML with XSLT

Subject: [xsl] Reprocessing XHTML with XSLT
From: Peter Flynn <peter@xxxxxxxxxxx>
Date: Thu, 31 Oct 2002 22:33:47 +0000
I've either lost those last few remaining neurons, or I've missed
something rather important in the documentation (it's the first
time I've needed to do an XML-to-XML transformation in anger, too :-)

I had a moderately well-formed HTML file from a user which I ran
through Tidy -asxml to turn it into WF XHTML. I mended some errors*
and it's now valid. I then started writing some XSLT (below) to turn
it into the required XML markup.

But running it through xt or Cocoon only fires the document root
template and nothing else, so I get output with the data content
enclosed in the specified root element tags (<modules>...</modules>)
and the rest is dogfood -- as if I had not specified any other
templates. I've tried with both the literal result elements and with
<xsl:element> but the same occurs.

Why is it failing to match the remaining templates? There doesn't seem
to be anything in Dave's FAQ or any of the books I've got, which only
cover XHTML *output*, so I'm making the conclusion that I've missed
something significant in the spec.

///Peter
--
Minimal example:

---------- test.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "/dtds/xhtml1-transitional.dtd">
<html>
  <head>
    <title>some title</title>
  </head>
  <body>
    <table>
      <tr>
	<td>stuff to ignore</td>
	<td>more stuff</td>
      </tr>
    </table>
    <h2>a heading</h2>
    <p>just text</p>
  </body>
</html>

---------- extract.xsl

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

<xsl:output method="xml"/>

<xsl:strip-space elements="*"/>

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

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

<xsl:template match="head | table | p"/>

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

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

</xsl:stylesheet>

---------- output

<?xml version="1.0" encoding="utf-8"?>
<modules>some titlestuff to ignoremore stuffa headingjust text</modules>

----------
* It appears that Tidy fails to convert NAME attributes which are
comprised of digits only to a suitable form beginning with a letter when
it outputs them as ID values, in order to conform with being XML Names.






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



Current Thread