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

Discussion in 'XML' started by Cameron McCormack, Jul 2, 2007.

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

    <xsl:eek:utput 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:x="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:x attribute is still in there, and
    how I can prevent it?

    Thanks,

    Cameron
    Cameron McCormack, Jul 2, 2007
    #1
    1. Advertising

  2. 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.
    Cameron McCormack, Jul 2, 2007
    #2
    1. Advertising

  3. 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:x='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:x 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/
    Martin Honnen, Jul 2, 2007
    #3
  4. 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:x 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!
    Cameron McCormack, Jul 3, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q29ybmUgUmFiZQ==?=

    Webservices SOAP and Namespace prefixes

    =?Utf-8?B?Q29ybmUgUmFiZQ==?=, Oct 26, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    5,849
    =?Utf-8?B?Q29ybmUgUmFiZQ==?=
    Oct 26, 2004
  2. Hubidubi
    Replies:
    1
    Views:
    504
    George Bina
    May 25, 2006
  3. Martin Honnen

    Re: exclude-result-prefixes

    Martin Honnen, Mar 14, 2007, in forum: XML
    Replies:
    1
    Views:
    674
    Simon Brooke
    Mar 14, 2007
  4. Alain Ketterlin

    Re: exclude-result-prefixes

    Alain Ketterlin, Mar 14, 2007, in forum: XML
    Replies:
    0
    Views:
    582
    Alain Ketterlin
    Mar 14, 2007
  5. Richard Tobin

    Re: exclude-result-prefixes

    Richard Tobin, Mar 14, 2007, in forum: XML
    Replies:
    6
    Views:
    690
    Simon Brooke
    Mar 19, 2007
Loading...

Share This Page