Re: exclude-result-prefixes

Discussion in 'XML' started by Martin Honnen, Mar 14, 2007.

  1. Simon Brooke wrote:

    > So, in summary, if anyone could educate me as to what
    > exclude-result-prefixes is really supposed to do (and why), and, as an
    > aside, how I can do what I thought it was meant to do, I'd be really
    > grateful.


    For your XSLT match patterns and/or XPath expressions you often need to
    declare prefixes bound to namespace URIs to use those prefixes in match
    patterns and/or XPath expressions while you might not want/need this
    prefixes in the result document as you do not have any result elements
    in those namespaces. In that case exclude-result-prefixes helps, it
    prevents the namespace declaration in the result document, but only if
    there are no result elements in those namespaces.

    In your example you however have result elements in the XHTML namespace
    http://www.w3.org/1999/xhtml and in that case the XSLT processor cannot
    exlude the prefix as that way the result document were no longer
    well-formed XML with namespaces.

    What you could do is e.g.

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    exclude-result-prefixes="xhtml">

    <xsl:eek:utput indent="yes" method="html"
    doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>

    <xsl:template match="xhtml:html">
    <html><body>Hello world!</body></html>
    </xsl:template>

    that way your result elements should be serialized in the default
    namespace e.g.
    <html xmlns="http://www.w3.org/1999/xhtml">
    as the XHTML 1.0 DTD wants it.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Mar 14, 2007
    #1
    1. Advertising

  2. Martin Honnen

    Simon Brooke Guest

    in message <45f823b7$0$20292$-online.net>, Martin
    Honnen ('') wrote:

    > Simon Brooke wrote:
    >
    >> So, in summary, if anyone could educate me as to what
    >> exclude-result-prefixes is really supposed to do (and why), and, as an
    >> aside, how I can do what I thought it was meant to do, I'd be really
    >> grateful.

    >
    > For your XSLT match patterns and/or XPath expressions you often need to
    > declare prefixes bound to namespace URIs to use those prefixes in match
    > patterns and/or XPath expressions while you might not want/need this
    > prefixes in the result document as you do not have any result elements
    > in those namespaces. In that case exclude-result-prefixes helps, it
    > prevents the namespace declaration in the result document, but only if
    > there are no result elements in those namespaces.
    >
    > In your example you however have result elements in the XHTML namespace
    > http://www.w3.org/1999/xhtml and in that case the XSLT processor cannot
    > exlude the prefix as that way the result document were no longer
    > well-formed XML with namespaces.
    >
    > What you could do is e.g.
    >
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    > xmlns:xhtml="http://www.w3.org/1999/xhtml"
    > xmlns="http://www.w3.org/1999/xhtml"
    > exclude-result-prefixes="xhtml">
    >
    > <xsl:eek:utput indent="yes" method="html"
    > doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
    >

    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
    >
    > <xsl:template match="xhtml:html">
    > <html><body>Hello world!</body></html>
    > </xsl:template>
    >
    > that way your result elements should be serialized in the default
    > namespace e.g.
    > <html xmlns="http://www.w3.org/1999/xhtml">
    > as the XHTML 1.0 DTD wants it.
    >


    Thanks!

    --
    (Simon Brooke) http://www.jasmine.org.uk/~simon/
    ;; Generally Not Used
    ;; Except by Middle Aged Computer Scientists
    Simon Brooke, Mar 14, 2007
    #2
    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. mayur
    Replies:
    2
    Views:
    1,012
    Natty Gur
    Jul 2, 2004
  2. Alain Ketterlin

    Re: exclude-result-prefixes

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

    Re: exclude-result-prefixes

    Richard Tobin, Mar 14, 2007, in forum: XML
    Replies:
    6
    Views:
    698
    Simon Brooke
    Mar 19, 2007
  4. Cameron McCormack
    Replies:
    3
    Views:
    14,940
    Cameron McCormack
    Jul 3, 2007
  5. Michael Tan
    Replies:
    32
    Views:
    960
    Ara.T.Howard
    Jul 21, 2005
Loading...

Share This Page