Using Tidy to correct XSL templates.

Mark El-Wakil <[email protected]>
Newsgroups gmane.comp.web.html-tidy.user
Message-ID <[email protected]>
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
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.