473,382 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

exclude-result-prefixes

I'm struggling to understand what 'exclude-result-prefixes' does and is
for; the language of the standard

http://www.zvon.org/xxl/XSLTreferenc...result-element

is not exactly easy to follow. What I assumed it was supposed to do is mark
specific prefixes as not to be printed in the generated document, but that
does not work with any of the XSL tools I'm currently working with (Xalan
1.2.2 and 2.7.0, xsltproc 1.1.19). Specifically, the following stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<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">

<xsl:output 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">
<xhtml:html><xhtml:body>Hello world!</xhtml:body></xhtml:html>
</xsl:template>

<xsl:template match="*">
<!-- nothing -->
</xsl:template>
</xsl:stylesheet>

generates

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xhtml:body>Hello world!</xhtml:body>
</xhtml:html>

from any HTML page using any current XSL processor that I have access to.

The specific reason I attacking this problem is that

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

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.
--
si***@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/
;; If God does not write LISP, God writes some code so similar to
;; LISP as to make no difference.
Mar 14 '07 #1
10 8481
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:output 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/
Mar 14 '07 #2
Simon Brooke <si***@jasmine.org.ukwrites:
I'm struggling to understand what 'exclude-result-prefixes' does and is
for; the language of the standard

http://www.zvon.org/xxl/XSLTreferenc...result-element
(BTW, the rec. is also available via www.w3c.org)

The purpose of exclude-result-prefixes is to avoid the output of
namespace declarations (xmlns:blah pseudo-attributes) that appear in
the source document but _never_ appear in the result document. It
means that if a namespace (like the XHTML namespace in your example)
is used in the result document, it will be declared in the output
(because it has to), whatever the value of exclude-result-prefixes is.
This is what you observe, since you use the XHTML ns in the output.

(The reason for this is that, if you declare a namespace in your
xsl:stylesheet element, all literal result elements are in the scope
of the namespace declaration, so a corresponding namespace
declaration is (may be) output, even if you do not use that namespace.)
<xsl:output 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">
<xhtml:html><xhtml:body>Hello world!</xhtml:body></xhtml:html>
</xsl:template>
This doesn't make much sense. You ask for HTML output, but provide
only namespace-qualified XML literal output. The XSLT rec. specifies
that the HTML output method "should not output an element differently
from the xml output method unless the expanded-name of the element has
a null namespace URI; an element whose expanded-name has a non-null
namespace URI should be output as XML" (sec 16.2). That means your
HTML-output request is ignored, because your result elements are
namespace-qualified (I'm talking about the <xhtml:htmlelement, _not_
the "xhtml:html" match pattern.)

If you need HTML output, to comply with browser requirements, use the
HTML output method and literal result elements that are in the null
namespace (i.e., have no namespace prefix, and such that
<xsl:stylesheetdoesn't declare a default namespace). If your
stylesheet outputs superfluous namespace declarations, add that
namespaces' prefixes to exclude-result-prefixes. Also, change the
public and system ids to point to HTML (no X).

-- Alain.
Mar 14 '07 #3
In article <41************@gododdin.internal.jasmine.org.uk >,
Simon Brooke <si***@jasmine.org.ukwrote:
>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.
Mar 14 '07 #4
In article <et***********@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.
Mar 14 '07 #5
in message <45***********************@newsspool3.arcor-online.net>, Martin
Honnen ('m********@yahoo.de') 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:output 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!

--
si***@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/
;; Generally Not Used
;; Except by Middle Aged Computer Scientists

Mar 14 '07 #6
in message <et***********@pc-news.cogsci.ed.ac.uk>, Richard Tobin
('r******@cogsci.ed.ac.uk') wrote:
In article <et***********@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 <si***@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?

--
si***@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
Mar 15 '07 #7
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
Mar 15 '07 #8
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
Mar 15 '07 #9
In article <bq************@gododdin.internal.jasmine.org.uk >,
Simon Brooke <si***@jasmine.org.ukwrote:
>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
<htmlelement. 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 <htmldownwards 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.
Mar 15 '07 #10
in message <et***********@pc-news.cogsci.ed.ac.uk>, Richard Tobin
('r******@cogsci.ed.ac.uk') wrote:
In article <bq************@gododdin.internal.jasmine.org.uk >,
Simon Brooke <si***@jasmine.org.ukwrote:
>>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
<htmlelement. Is it literally there in the stylesheet?
No, it's one of a number of generally similar <pelements copied from the
source document, which is not namespace-aware. However, although the
validator reported the error only for the first <pelement it
encountered, in fact all the copied elements were so decorated.

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

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

;; lovely alternative to rice.
Mar 20 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John Field | last post by:
Hello, Is it possible to exclude certain files in a wx.FileDialog, so that the user won't see them and can't select them with the mouse in de File open window? I was thinking of somehow...
15
by: could ildg | last post by:
In re, the punctuation "^" can exclude a single character, but I want to exclude a whole word now. for example I have a string "hi, how are you. hello", I want to extract all the part before the...
1
by: Rajesh Abraham | last post by:
I would like to Exclude MyApp.Exe.Config from my Setup Package as I don't want it to get overwritten during upgrade installation of my application. If I remove app.config while building the...
4
by: Glen Parker | last post by:
Since pg_dump will be allowing multiple -t <table> parameters for 8.0, here is a related feature request. A similar option (allowing multiples also) to EXCLUDE tables, so we can do a dump of the...
1
by: John Dalberg | last post by:
In VS 2003, I was able to exclude full folders from a project but I can't do the same in VS 2005. I can exclude files but not folders. I prefer to exclude at the folder level because the folder...
9
by: paul.jameson | last post by:
I have a simple Access database that stores Karaoke Songlists for my local pub. From this you are able to print out the song lists they use. Up until now, any duplicate songs that appear on say,...
2
by: Arsen V. | last post by:
Hi, How to exclude the App_Data directory from Visual SourceSafe? It appears that Vs 2005 automatically adds the App_Data directory with the large binary MDF and LOG files to the Visual...
3
by: KJ | last post by:
Hello All, Can someone please explain what these .exclude/.include files are? They only show up in some web site projects, and it seems to be related to deleting. Any ideas?
1
by: AntiChrist | last post by:
In VS 2005 if you exclude files from a project, it actually renames the file to filename.exclude. In previous versions, it just left the file alone but excluded it. If you have a very large...
3
by: ITSimTech | last post by:
I'm trying to learn how/do two things here: 1) If the user searches for "Data" ($searchtext = "Data") the output should also include the fourth record because Field1 contains "all". 2) But the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.