Re: [xslt] Can anyone help with this?



Hi,

You may want to try the following:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns="http://www.w3.org/1999/xhtml";
  xmlns:xhtml="http://www.w3.org/1999/xhtml";>
  <xsl:output method="xml" indent="yes" doctype-public="-//W3C//DTD
XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

  <xsl:template match="/xhtml:base">
    <html>
      <head>
        <title>
          <xsl:value-of select="xhtml:title"/>
        </title>
      </head>
      <body>
        <!-- This almost works but creates poor namespace issues -->
        <xsl:copy-of select="xhtml:body/*"></xsl:copy-of>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

<?xml version="1.0"?>
<base xmlns="http://www.w3.org/1999/xhtml";>
  <title>Test Title</title>
  <body>
    <p>Test Paragraph</p>
  </body>
</base>

Since your input element "p" was in no namespace, its copy will also
stay
in no namespace in the result tree. The xmlns="" was added to disable
the default namespace for "p".

Regards,

Kasimier


> -----Original Message-----
> From: xslt-bounces gnome org [mailto:xslt-bounces gnome org] 
> On Behalf Of nathan bullock
> Sent: Thursday, June 22, 2006 6:06 PM
> To: xslt gnome org
> Subject: [xslt] Can anyone help with this?
> 
> I have this xsl document "test.xsl"
> 
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
>         xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>         xmlns="http://www.w3.org/1999/xhtml";>
>     <xsl:output method="xml" indent="yes"
>         doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
>         
> doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
> 
> <xsl:template match="/base">
> <html><head>
> 	<title><xsl:value-of select="title"/></title>
> </head><body>
> 
> <!-- This almost works but creates poor namespace issues -->
> <xsl:copy-of select="body/*"></xsl:copy-of>
> 
> </body>
> 
> </html>
> </xsl:template>
> </xsl:stylesheet>
> 
> And this xml document "test.xml"
> 
> <?xml version="1.0"?>
> <base>
> <title>Test Title</title>
> <body>
> <p>Test Paragraph</p>
> </body>
> </base>
> 
> And when I apply the transformation I get
> 
> <?xml version="1.0"?>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
> <html xmlns="http://www.w3.org/1999/xhtml";>
>   <head>
>     <meta http-equiv="Content-Type" content="text/html; 
> charset=UTF-8" />
>     <title>Test Title</title>
>   </head>
>   <body>
>     <p xmlns="">Test Paragraph</p>
>   </body>
> </html>
> 
> But if you notice this leaves ugly little xmlns="" in the document.
> How do I get rid of these? I can't seem to figure it out. Basically I
> want to be able to recursively copy a chunk of elements into my xhtml
> document and be able to use the proper namespace while inserting them.
> 
> Nathan Bullock
> 
> ps. This is the python file I am using to do the conversion:
> 
> import libxml2
> import libxslt
> 
> def transform(str_xml, str_xsl, out):
>     styledoc = libxml2.parseFile(str_xsl)
>     style = libxslt.parseStylesheetDoc(styledoc)
>     doc = libxml2.parseFile(str_xml)
>     result = style.applyStylesheet(doc, None)
>     style.saveResultToFilename(out, result, 0)
>     style.freeStylesheet()
>     doc.freeDoc()
>     result.freeDoc()
> 
> transform("test.xml", "test.xsl", "out1.html")
> _______________________________________________
> xslt mailing list, project page http://xmlsoft.org/XSLT/
> xslt gnome org
> http://mail.gnome.org/mailman/listinfo/xslt
> 
> 



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