Using Tidy to correct XSL templates.

View: New views
2 Messages — Rating Filter:   Alert me  

Using Tidy to correct XSL templates.

by Mark El-Wakil :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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; -->
 

<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; -->
     
    <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; -->
   </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@...



Re: Using Tidy to correct XSL templates.

by Bjoern Hoehrmann :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

* Mark El-Wakil wrote:
>I'm currently looking to use Tidy as a method of cleaning up XSL
>templates, if possible.

Tidy's XML parser and pretty printer may modify the white space in the
document in ways that you do not wish it to, that would already make it
an unsuitable tool for this task. It also does not know anything about
XSLT, so you cannot expect any context-aware processing. I would suggest
to use some other tool, perhaps libxml2's xmllint does a better job with
the recover option, I would not count on it though.

>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.

No.

>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?

Probably not.
--
Björn Höhrmann · mailto:bjoern@... · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/