Re: [xslt] xsltproc/libxslt



Hi Siegfried,
    I think the crucial thing you're missing from your stylesheet is setting the output method to 'html'.
    Also, the <script /> tag IS valid, it's just that IE doesn't parse it because it's rubbish.

Try this:
XML:
<doc>
   <js file="java.script"/>
   <para>Funfunfunfunfunfun</para>
   <textinput class="fun"/>
</doc>

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

   <xsl:template match="/">
      <html>
         <head>
            <title>Test</title>
            <xsl:apply-templates match="js"/>
         </head>
         <body>
            <xsl:apply-templates />
         </body>
      </html>
   </xsl:template>

   <xsl:template match="js">
      <script type="text/_javascript_" src=""></script>
   </xsl:template>

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

   <xsl:template match="textinput">
      <textarea class="{ class}" name="textin"></textarea>
   </xsl:template>
</xsl:stylesheet>

Results in the following output from xsltproc:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test</title>
   <script type="text/_javascript_" src=""></script>
   <p>Funfunfunfunfunfun</p>
   <textarea class="fun" name="textin"></textarea>
</head>
<body>
   <script type="text/_javascript_" src=""></script>
   <p>Funfunfunfunfunfun</p>
   <textarea class="fun" name="textin"></textarea>
</body>
</html>


As you can see, it preserves the end-tags for textarea and script.

Toby.

Siegfried Gipp wrote:
Hi,

while xsltproc is working fine with xml and xhtml documents it has some errors 
in outputting html. I'm currently using a sed file to correct them:

1,3s/\/\/EN\"\"http/\/\/EN\" \"http/
s#xmlns=\"http://www.w3.org/1999/xhtml\"##g
s#/>#>#g
s/\&action/\&amp;action/g
s#<link\([^>]*\)></link>#<link\1>#g
s#<meta\([^>]*\)></meta>#<meta\1>#g
s#<input\([^>]*\)></input>#<input\1>#g
s#<br></br>#<br>#g
s#<hr></hr>#<hr>#g
s#<textarea\([^>]*\)/>#<textarea\1></textarea>#g
s#<script\([^>]*\)/>#<script\1></script>#g


The first line throws in an extra space in the DOCTYPE.
The second line is possibly not necessary, but html pages do not validate at 
w3c with a namespace.
The third line removes those shorthand tag endings since the validator throws 
warnings about that.

The next three lines do correct real invalid html. In html it is not allowed 
to write <meta name="..." content=".."></meta>. Although this is correct in 
xml, it is not in html. The same is for input, hr and br. 
The opposite is true for <script>. This must always be written in the form 
<script></script> in html even if there is no content. Anything other is 
invalid.

Regards
Siegfried
_______________________________________________
xslt mailing list, project page http://xmlsoft.org/XSLT/
xslt gnome org
http://mail.gnome.org/mailman/listinfo/xslt
  


-- 
Toby Cole
Software Engineer

Semantico
Lees House, Floor 1, 21-23 Dyke Road, Brighton BN1 3FE
T: +44 (0)1273 358 238
F: +44 (0)1273 723 232
E: toby cole semantico com
W: www.semantico.com 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]