Go Back   Velocity Reviews > Newsgroups > XML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

XML - XSLT exclude-result-prefixes not preventing namespace declaration in output

 
Thread Tools Search this Thread
Old 07-02-2007, 02:45 AM   #1
Default XSLT exclude-result-prefixes not preventing namespace declaration in output


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='http://mcc.id.au/
ns/local'>
<head>
<title>blah</title>
</head>
<body>
<x:something/>
</body>
</html>

And this is the XSLT I'm using:

<xsl:stylesheet xmlnssl='http://www.w3.org/1999/XSL/Transform'
xmlns:h='http://www.w3.org/1999/xhtml'
xmlns='http://mcc.id.au/ns/local'
xmlns='http://www.w3.org/1999/xhtml'
exclude-result-prefixes='h x'
version='1.0'>

<xslutput method='xml' encoding='UTF-8'
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="http://mcc.id.au/
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 attribute is still in there, and
how I can prevent it?

Thanks,

Cameron



Cameron McCormack
  Reply With Quote
Old 07-02-2007, 02:57 AM   #2
Cameron McCormack
 
Posts: n/a
Default Re: XSLT exclude-result-prefixes not preventing namespace declaration in output

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.

  Reply With Quote
Old 07-02-2007, 12:53 PM   #3
Martin Honnen
 
Posts: n/a
Default Re: XSLT exclude-result-prefixes not preventing namespace declarationin output

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='http://mcc.id.au/
> 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 use
<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/
  Reply With Quote
Old 07-03-2007, 01:06 AM   #4
Cameron McCormack
 
Posts: n/a
Default Re: XSLT exclude-result-prefixes not preventing namespace declaration in output

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 use
> <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!

  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump