Re: exclude-result-prefixes

Discussion in 'XML' started by Richard Tobin, Mar 14, 2007.

  1. In article <>,
    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.


    Despite its name, exclude-result-prefixes specifies *namespaces* for
    which prefixes are not needed, rather than expressing your choice of
    prefixes. It does this by listing prefixes bound to those namespaces,
    which explains the name.

    What it's good for is avoiding prefix declarations for namespaces that
    aren't used in the output document. If your stylesheet declares a
    prefix xmlns:foo="http://example.org" to access elements from the
    source document which are in that namespace, but your output document
    doesn't have anything from that namespace, then you can use
    exclude-result-prefixes to avoid the spurious declaration (which would
    otherwise be likely to appear because any literal result elements in the
    stylesheet would have it in-scope).

    As to your requirements:

    > (1) Older browsers barf at 'xhtml:html' and other such tagnames; and
    > (2) The W3C validator barfs at 'xmlns'


    I'm very surprised by (2). However, the DTD declares the html
    element as

    <!ELEMENT html (head, body)>
    <!ATTLIST html
    %i18n;
    id ID #IMPLIED
    xmlns %URI; #FIXED 'http://www.w3.org/1999/xhtml'
    >


    so it should work to generate output with no namespaces, and the FIXED
    attribute in the DTD will make it use the xhtml namespace when it's
    read back in again.

    -- Richard
    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
    Richard Tobin, Mar 14, 2007
    #1
    1. Advertising

  2. In article <et9afu$1gma$>, I wrote:

    >> (1) Older browsers barf at 'xhtml:html' and other such tagnames; and
    >> (2) The W3C validator barfs at 'xmlns'

    >
    >I'm very surprised by (2). However, the DTD declares the html
    >element as
    >
    ><!ELEMENT html (head, body)>
    ><!ATTLIST html
    > %i18n;
    > id ID #IMPLIED
    > xmlns %URI; #FIXED 'http://www.w3.org/1999/xhtml'
    > >

    >
    >so it should work to generate output with no namespaces, and the FIXED
    >attribute in the DTD will make it use the xhtml namespace when it's
    >read back in again.


    Henry Thompson reminds me that if you do this you will need to specify
    <xsl:eek:utput method="xml"/> because otherwise it will use HTML output
    mode.

    -- Richard
    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
    Richard Tobin, Mar 14, 2007
    #2
    1. Advertising

  3. Richard Tobin

    Simon Brooke Guest

    in message <et9ar4$1gma$>, Richard Tobin
    ('') wrote:

    > In article <et9afu$1gma$>, I wrote:
    >
    >>> (1) Older browsers barf at 'xhtml:html' and other such tagnames; and
    >>> (2) The W3C validator barfs at 'xmlns'

    >>
    >>I'm very surprised by (2). However, the DTD declares the html
    >>element as
    >>
    >><!ELEMENT html (head, body)>
    >><!ATTLIST html
    >> %i18n;
    >> id ID #IMPLIED
    >> xmlns %URI; #FIXED 'http://www.w3.org/1999/xhtml'
    >> >

    >>
    >>so it should work to generate output with no namespaces, and the FIXED
    >>attribute in the DTD will make it use the xhtml namespace when it's
    >>read back in again.

    >
    > Henry Thompson reminds me that if you do this you will need to specify
    > <xsl:eek:utput method="xml"/> because otherwise it will use HTML output
    > mode.


    I am moving in elite circles :)

    Right. To specifics. Consider the page at:
    http://www.weft.co.uk/customers/xylodom/redesign200703/samples/sample_item_single_variant.html

    It fails validation with just one error:

    Error Line 83 column 17: there is no attribute "xmlns".

    <p xmlns="http://www.w3.org/1999/xhtml">

    I'd really like to generate a page which passes validation. The preamble of
    the XSL transform concerned is:

    <?xml version="1.0" encoding="utf-8"?>

    <!DOCTYPE stylesheet [
    <!ENTITY nbsp " ">
    <!ENTITY pound "£">
    ]>

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

    <!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
    <!-- -->
    <!-- show_item_single_variant.xsl -->
    <!-- -->
    <!-- Purpose: -->
    <!-- Transform show_item output for Xylodom -->
    <!-- Incorporates information from variants into body, -->
    <!-- does not link to variants pages. -->
    <!-- -->
    <!-- Author: Simon Brooke <> -->
    <!-- Created: 14th March 2007 -->
    <!-- $Revision: 1.10 $ -->
    <!-- Copyright: (c) 2007 Simon Brooke -->
    <!-- -->
    <!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->

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


    The element in the source document from which the errant paragraph was
    generated is:

    <p>
    We cut and supply beams for many different building projects
    across the UK, including beams for roof and timber frame construction,
    historical restoration, boat building, mantels and fire surrounds.
    </p>

    - it doesn't have anything fancy about it. The only template in the
    transform which processes this paragraph is:

    <!-- by default just copy everything through -->
    <xsl:template match="@* | node()">
    <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
    </xsl:template>

    So: /why/ is an xmlns attribute being generated for that element (and, why
    oh why, just that element), and how do I say politely that I'd really very
    much rather it were not generated?

    --
    (Simon Brooke) http://www.jasmine.org.uk/~simon/
    "The result is a language that... not even its mother could
    love. Like the camel, Common Lisp is a horse designed by
    committee. Camels do have their uses."
    ;; Scott Fahlman, 7 March 1995
    Simon Brooke, Mar 15, 2007
    #3
  4. Simon Brooke wrote:
    > Error Line 83 column 17: there is no attribute "xmlns".
    > <p xmlns="http://www.w3.org/1999/xhtml">

    [...]
    > So: /why/ is an xmlns attribute being generated for that element

    (and, why
    > oh why, just that element), and how do I say politely that I'd really

    very
    > much rather it were not generated?


    XML namespace declarations are inherited downward. When the stylesheet
    copies an element into a new document, it may copy the namespace
    declaration in order to be sure it is preserved.

    The folks who designed the transitional DTD didn't allow for redundant
    namespace declarations. One can argue about whether that was sloppy or not.

    The simplest fix is to discard DTD validation and switch to schema
    validation -- or to give up validation and stick with well-formed.

    The next-simplest fix is to make sure the default namespace is
    explicitly declared on the outermost element, *HOPE* that your
    stylesheet processor is clever enough to recognize that namespaces
    already in scope don't have to be redeclared, and be extremely careful
    never to allow the default namespace to become anything else (which
    would force redeclaration).

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Mar 15, 2007
    #4
  5. Simon Brooke wrote:

    > So: /why/ is an xmlns attribute being generated for that element (and, why
    > oh why, just that element), and how do I say politely that I'd really very
    > much rather it were not generated?
    >


    because that element is being copied and it's in the xhtml namespace,
    but you've generated all its parent elements in no-namespace (which
    means thay are not xhtml as far as the xslt system knows)
    just add
    xmlns="http://www.w3.org/1999/xhtml"
    to your xsl:stylesheet so that this is the default namespace and all
    literal result elements in the stylesheet are xhtml.

    Alternatively, if your source is xhtml but you want to generate
    no-namespace elements don't use xsl:copy in your default template, use
    <xsl:element name="{local-name()}">
    which will generate an element with the same local name as the source
    but with the default namespace of the stylesheet 9which is no-namespace
    by default)

    David
    David Carlisle, Mar 15, 2007
    #5
  6. In article <>,
    Simon Brooke <> wrote:

    >Right. To specifics. Consider the page at:
    >http://www.weft.co.uk/customers/xylodom/redesign200703/samples/sample_item_single_variant.html
    >
    >It fails validation with just one error:
    >
    >Error Line 83 column 17: there is no attribute "xmlns".
    >
    > <p xmlns="http://www.w3.org/1999/xhtml">


    Others have explained the problem. But the mystery is why none of
    your *other* XHTML elements are in the XHTML namespace. You
    haven't shown us the stylesheet code that generates the top-level
    <html> element. Is it literally there in the stylesheet?

    [Of course they are in the XHTML namespace as far as the browser is
    concerned, because of the #FIXED attribute in the DTD. But XSLT
    thinks it's outputting elements in no namespace.]

    To get DTD validity, you need to ensure that XSLT believes either
    (a) that all the elements from <html> downwards are in the XHTML
    namespace, or (b) that all the elements - including the <p> - are
    in no namespace, and allow the DTD to "fix" it for the browser.

    To do (a), you probably need to make the XHTML namespace be the
    default namespace in the stylesheet itself, otherwise XSLT will use
    your prefix for it, and you said browsers don't like that. To do (b),
    you need to ensure that all the elements you copy are in no namespace.
    Overall, you may well feel that getting DTD validity isn't worth the
    trouble.

    -- Richard
    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
    Richard Tobin, Mar 15, 2007
    #6
  7. Richard Tobin

    Simon Brooke Guest

    in message <etcg16$2gq4$>, Richard Tobin
    ('') wrote:

    > In article <>,
    > Simon Brooke <> wrote:
    >
    >>Right. To specifics. Consider the page at:
    >>http://www.weft.co.uk/customers/xylodom/redesign200703/samples/sample_item_single_variant.html
    >>
    >>It fails validation with just one error:
    >>
    >>Error Line 83 column 17: there is no attribute "xmlns".
    >>
    >> <p xmlns="http://www.w3.org/1999/xhtml">

    >
    > Others have explained the problem. But the mystery is why none of
    > your *other* XHTML elements are in the XHTML namespace. You
    > haven't shown us the stylesheet code that generates the top-level
    > <html> element. Is it literally there in the stylesheet?


    No, it's one of a number of generally similar <p> elements copied from the
    source document, which is not namespace-aware. However, although the
    validator reported the error only for the first <p> element it
    encountered, in fact all the copied elements were so decorated.

    So the solution given by others is undoubtedly the right solution.

    --
    (Simon Brooke) http://www.jasmine.org.uk/~simon/

    ;; lovely alternative to rice.
    Simon Brooke, Mar 19, 2007
    #7
    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. Martin Honnen

    Re: exclude-result-prefixes

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

    Re: exclude-result-prefixes

    Alain Ketterlin, Mar 14, 2007, in forum: XML
    Replies:
    0
    Views:
    588
    Alain Ketterlin
    Mar 14, 2007
  4. Cameron McCormack
    Replies:
    3
    Views:
    14,937
    Cameron McCormack
    Jul 3, 2007
  5. Michael Tan
    Replies:
    32
    Views:
    957
    Ara.T.Howard
    Jul 21, 2005
Loading...

Share This Page