![]() |
Re: exclude-result-prefixes
In article <41ilc4-vlb.ln1@gododdin.internal.jasmine.org.uk>,
Simon Brooke <simon@jasmine.org.uk> 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. |
Re: exclude-result-prefixes
In article <et9afu$1gma$2@pc-news.cogsci.ed.ac.uk>, 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:output 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. |
Re: exclude-result-prefixes
in message <et9ar4$1gma$3@pc-news.cogsci.ed.ac.uk>, Richard Tobin
('richard@cogsci.ed.ac.uk') wrote: > In article <et9afu$1gma$2@pc-news.cogsci.ed.ac.uk>, 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:output 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" 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 <simon@weft.co.uk> --> <!-- Created: 14th March 2007 --> <!-- $Revision: 1.10 $ --> <!-- Copyright: (c) 2007 Simon Brooke --> <!-- --> <!-- :::::::::::::::::::::::::::::::::::::::::::::::::: ::::::: --> <xsl:output 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@jasmine.org.uk (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 |
Re: exclude-result-prefixes
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 |
Re: exclude-result-prefixes
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 |
Re: exclude-result-prefixes
In article <bqhoc4-5bc.ln1@gododdin.internal.jasmine.org.uk>,
Simon Brooke <simon@jasmine.org.uk> 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. |
Re: exclude-result-prefixes
in message <etcg16$2gq4$1@pc-news.cogsci.ed.ac.uk>, Richard Tobin
('richard@cogsci.ed.ac.uk') wrote: > In article <bqhoc4-5bc.ln1@gododdin.internal.jasmine.org.uk>, > Simon Brooke <simon@jasmine.org.uk> 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. -- simon@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/ ;; lovely alternative to rice. |
| All times are GMT. The time now is 08:23 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.