W3C home > Mailing lists > Public > html-tidy@w3.org > April to June 2009

Using Tidy to correct XSL templates.

From: Mark El-Wakil <mark@seventhcycle.net>
Date: Fri, 01 May 2009 17:39:55 -0700
Message-ID: <49FB965B.8010107@seventhcycle.net>
To: html-tidy@w3.org
Hello,

I'm currently looking to use Tidy as a method of cleaning up XSL 
templates, if possible.  To test it out, I have a very simple stylesheet:

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

<!-- Test 1: See if image tag is fixed -->
<img src="/members/images/header.jpg">

test

<!-- Test 2: nbsp; -->
&nbsp;

<xsl:for-each select="/root/page">
 <xsl:value-of select="." />
</xsl:for-each>

</xsl:template>
</xsl:stylesheet>

Pretty simple.  It contains the two most common errors that people do 
when trying to create an XSL template

My problem is twofold:

1) If I just try and parse XML in this file, I get a result like this:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <!-- Test 1: See if image tag is fixed -->
    <img src="/members/images/header.jpg">ok?
    <!-- Test 2: nbsp; -->
    &#160;
    <xsl:for-each select="/root/page">
      <xsl:value-of select="." />
    </xsl:for-each></img>
  </xsl:template>
</xsl:stylesheet>

In this case, the <img> tag ends up encompassing whatever is underneath it.

2) On the other hand, if I go ahead and try to do this with XHTML

<?xml version="1.0"?>
<html>
  <head>
    <!-- Test 1: See if image tag is fixed -->
    <title></title>
  </head>
  <body>
  <img src="/members/images/header.jpg" /> ok?
  <!-- Test 2: nbsp; -->
  &nbsp;</body>
</html>

Anything with a namespace of xsl (like <xsl:template>) gets removed, and 
surrounding <html> tags are added, since HTML is added.

What I'm looking for / wondering with Tidy is either:

a) Can I run tidy on my xsl file in XHTML mode where it doesn't try and 
create <html>, <head> and <body> tags to wrap around my code.

or

b) Can I run tidy in XML mode, and specify specific tags like IMG or BR 
to auto-correct in a way that the tag gets closed immediately?  So that 
<br> becomes <br /> and the like, without having to treat it like HTML?

Thanks,
Mark El-Wakil
mark@seventhcycle.net
Received on Sunday, 3 May 2009 02:06:35 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 3 April 2012 06:13:59 GMT