Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Re: exclude-result-prefixes

Reply
Thread Tools

Re: exclude-result-prefixes

 
 
Richard Tobin
Guest
Posts: n/a
 
      03-14-2007
In article <(E-Mail Removed)>,
Simon Brooke <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      03-14-2007
In article <et9afu$1gma$(E-Mail Removed)>, 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
<xslutput 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.
 
Reply With Quote
 
 
 
 
Simon Brooke
Guest
Posts: n/a
 
      03-15-2007
in message <et9ar4$1gma$(E-Mail Removed)>, Richard Tobin
('(E-Mail Removed)') wrote:

> In article <et9afu$1gma$(E-Mail Removed)>, 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
> <xslutput 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/xylo...e_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"
xmlnssl="http://www.w3.org/1999/XSL/Transform"
xmlnshtml="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 <(E-Mail Removed)> -->
<!-- Created: 14th March 2007 -->
<!-- $Revision: 1.10 $ -->
<!-- Copyright: (c) 2007 Simon Brooke -->
<!-- -->
<!-- :::::::::::::::::::::::::::::::::::::::::::::::::: ::::::: -->

<xslutput 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?

--
http://www.velocityreviews.com/forums/(E-Mail Removed) (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


 
Reply With Quote
 
Joseph Kesselman
Guest
Posts: n/a
 
      03-15-2007
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
 
Reply With Quote
 
David Carlisle
Guest
Posts: n/a
 
      03-15-2007
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
 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      03-15-2007
In article <(E-Mail Removed)>,
Simon Brooke <(E-Mail Removed)> wrote:

>Right. To specifics. Consider the page at:
>http://www.weft.co.uk/customers/xylo...e_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.
 
Reply With Quote
 
Simon Brooke
Guest
Posts: n/a
 
      03-19-2007
in message <etcg16$2gq4$(E-Mail Removed)>, Richard Tobin
('(E-Mail Removed)') wrote:

> In article <(E-Mail Removed)>,
> Simon Brooke <(E-Mail Removed)> wrote:
>
>>Right. To specifics. Consider the page at:
>>http://www.weft.co.uk/customers/xylo...e_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.

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

;; lovely alternative to rice.


 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments