xsl-list
[Top] [All Lists]

Re: xslt & doctype problem

2005-10-17 00:33:25
Hi,

I find it counter-intuitive, but it is best to always put the most generic templates above specific ones. Especially when not using priorities on templates..

HTH,
Geert

Glyph wrote:
I have a problem whereby if I include an xhtml doctype declaration in my

html then my xslt templates always match the wildcard.

Ive constructed a simple demonstration of a problem Im having, hoping a sage older hand can tell me where Ive gone wrong. It includes a simple transform, and two xhtml files which have two minor differences: in the second I include the DOCTYPE declaration, and can thus use the nbsp by name.

If I process them with xalan 2.7 (I had similar problems with msxml, and switched because I hoped xalan might be different) the 'head' and 'body' tags in the second file is always matched by the wildcard template.

java.exe -classpath %CLASSPATH% org.apache.xalan.xslt.Process -IN dummy.html -XSL dummy-clean.xslt

java.exe -classpath %CLASSPATH% org.apache.xalan.xslt.Process -IN dummy2.html -XSL dummy-clean.xslt

Hoping its something stupid (and thus easy to fix)
-G.

----- clean.xslt ---------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>

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

<xsl:output
method="html"
version="4.0"
encoding="iso-8859-1" indent="yes"
omit-xml-declaration="yes"/>

<!-- start at root of document -->
<xsl:template match="/">
  <xsl:message terminate="no">
      Trace: root -<xsl:value-of select="name()" />-
  </xsl:message>
  <html>
      <xsl:apply-templates select="*" />
  </html>
</xsl:template>

<xsl:template match="html">
  <xsl:message terminate="no">
      Trace: html
  </xsl:message>
<xsl:copy>
  <xsl:apply-templates select="*" />
</xsl:copy>
</xsl:template>

<xsl:template match="head">
  <xsl:message terminate="no">
      Trace: head
  </xsl:message>
<xsl:copy>
  <xsl:if test="not(title)">
  <title> No Title Given </title>
  </xsl:if>
  <xsl:apply-templates />
</xsl:copy>
</xsl:template>

<xsl:template match="body">
  <xsl:message terminate="no">
      Trace: body
  </xsl:message>
<xsl:copy>
  <h1>
      <!-- potentially empty header -->
      <xsl:copy-of select="../head/title" />
  </h1>
  <xsl:apply-templates mode="inner" />
</xsl:copy>
</xsl:template>

<!-- copy generic nodes -->
<xsl:template match="*">
<xsl:copy>
  <xsl:copy-of select="@*" />
  <xsl:message terminate="no">
      Trace: generic -<xsl:value-of select="name()" />-
  </xsl:message>
  <xsl:apply-templates />
</xsl:copy>
</xsl:template>

<!-- copy generic nodes without trace -->
<xsl:template mode="inner" match="*">
<xsl:copy>
  <xsl:copy-of select="@*" />
  <xsl:apply-templates mode="inner" />
</xsl:copy>
</xsl:template>

</xsl:transform>
------------------------------------------


----dummy.html--------------------------
<html>
<head>
<meta name="fish" value="Carp" />
</head>
<body>
<h1>carp</h1>
<p>Im not going to harp on about carp</p>
<p>Just going to include a simple &#160;</p>
</body>
</html>
------------------------------------------


----dummy2.html--------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>

<html>
<head>
<meta name="fish" value="Carp" />
</head>
<body>
<h1>carp</h1>
<p>Im not going to harp on about carp</p>
<p>Just going to include a simple &nbsp;</p>
</body>
</html>
------------------------------------------


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--
Drs. G.P.H. Josten
Consultant



Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665  JZ  Bleiswijk
Tel: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
www.daidalos.nl


De informatie - verzonden in of met dit emailbericht - is afkomstig van Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit bericht kunnen geen rechten worden ontleend.


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>