![]() |
|
|
|||||||
![]() |
XML - XSLT exclude-result-prefixes not preventing namespace declaration in output |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Hi everyone.
I'm having trouble working out why exclude-result-prefixes isn't preventing a namespace declaration in my output document. This is my input document: <html xmlns='http://www.w3.org/1999/xhtml' xmlns ns/local'> <head> <title>blah</title> </head> <body> <x:something/> </body> </html> And this is the XSLT I'm using: <xsl:stylesheet xmlns xmlns:h='http://www.w3.org/1999/xhtml' xmlns xmlns='http://www.w3.org/1999/xhtml' exclude-result-prefixes='h x' version='1.0'> <xsl doctype-public='-//W3C//DTD XHTML 1.0 Strict//EN' doctype-system='http://www.w3.org/TR/xhtml1/DTD/xhtml1- strict.dtd' media-type='application/xhtml+xml; charset=UTF-8'/> <xsl:template match='/'> <xsl:apply-templates select='/*'/> </xsl:template> <xsl:template match='h:*'> <xsl:copy> <xsl:copy-of select='@*'/> <xsl:apply-templates select='node()'/> </xsl:copy> </xsl:template> </xsl:stylesheet> When I run xsltproc to transform the input document, I get this output: <?xml version="1.0" encoding="UTF-8"?> <!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" xmlns ns/local"> <head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>blah</title> </head> <body> </body> </html> Could someone explain why the xmlns how I can prevent it? Thanks, Cameron Cameron McCormack |
|
|
|
|
#2 |
|
Posts: n/a
|
Cameron McCormack:
> I'm having trouble working out why exclude-result-prefixes isn't > preventing a namespace declaration in my output document. And please excuse Google Groups sticking in unwanted line breaks. |
|
|
|
#3 |
|
Posts: n/a
|
Cameron McCormack wrote:
> I'm having trouble working out why exclude-result-prefixes isn't > preventing a namespace declaration in my output document. > > This is my input document: > > <html xmlns='http://www.w3.org/1999/xhtml' xmlns > ns/local'> > <xsl:template match='h:*'> > <xsl:copy> xsl:copy copies the element including any namespace nodes that are in scope. And for your elements the default namespace is in scope but the other namespace is in scope too. exclude-result-prefixes only helps to prevent namespace declarations used in the stylesheet, not those copied from the input XML. So to get rid of the xmlns <xsl:template match="h:*"> <xsl:element name="{name()}" namespace="{namespace-uri()}"> that way the element is copied but not any additional namespace nodes that are in scope. -- Martin Honnen http://JavaScript.FAQTs.com/ |
|
|
|
#4 |
|
Posts: n/a
|
Martin Honnen:
> xsl:copy copies the element including any namespace nodes that are in > scope. And for your elements the default namespace is in scope but the > other namespace is in scope too. exclude-result-prefixes only helps to > prevent namespace declarations used in the stylesheet, not those copied > from the input XML. > So to get rid of the xmlns > <xsl:template match="h:*"> > <xsl:element name="{name()}" namespace="{namespace-uri()}"> > that way the element is copied but not any additional namespace nodes > that are in scope. Ah, great, that did the trick. Thanks! |
|