xsl:copy-of does not work for copying xhtml elements from xml input file




14 years ago
13 years ago


(Reporter: cking, Assigned: peterv)


Windows 98

Firefox Tracking Flags

(Not tracked)





14 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.7) Gecko/20040626 Firefox/0.8
Build Identifier: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.7) Gecko/20040626 Firefox/0.8

The xml contains a few html elements we want to copy into the result tree.

This can be done with <xsl:copy-of select="."/>, but doing so causes all
formatting to disappear in Mozilla/Firefox. It's as if only the text nodes come
through, not the element tags and attributes.

Reproducible: Always
Steps to Reproduce:
1. open test-copy-of.xml
2. open test-copy-of.html

Actual Results:  
step 1: formatting and style information has disappeared
step 2: looks OK

Expected Results:  
both should display the same

see URL
Without having looked at the testcase I can almost promice this is INVALID. If
you are creating XHTML output you need to make sure all elements are in the
XHTML namespace. If they are not then they will be treated like plain XML
elements with no HTML semantics or formatting at all.

Note that IE treats everything as HTML and ignores namespaces compleatly. Which
is why it "works" in IE.
Oh, I forgot to say that xsl:copy-of copies both name and namespace. So the
created element will have the same namespace in the output document as it has in
the source XML document (which I would guess is the null-namespace in your case)

Comment 3

14 years ago
(wow that's a quick answer)
but... OK that IE treats everything as HTML, but what about Saxon?
btw. I have tried to solve this by separating namespaces but to no avail

Comment 4

14 years ago
also... if this would be a namespace issue, how come then that my "workaround"
works? (building a copy 'manually', resulting in just normal <p> elements (not
<html:p> or whatever - but it works)
Saxon seems to do the same thing we do. Look at the namespaces generated, those
p-tags are not in the xhtml namespace. However since you save the file as HTML
it gets passed through the html-parser which treats everything as HTML and
doesn't know anything about namespace (which is correct).

I don't see where you use the "workaround", but if you are creating elements
using either normal <p> or using <xsl:element name="name(.)"> then you'll get
the namespace from the stylesheet.

However this is not the forum for generic XSLT questions. Use some mailing list
or newsgroup for that. I'd suggest the one at
Last Resolved: 14 years ago
Resolution: --- → INVALID
Of course, the simple solution is that you create HTML rather then XHTML.
That'll probably save you a lot of other headaches too.

Comment 7

14 years ago
Thanks, you were right it was a namespace error. The problem is fixed by putting
the xhtml elements inside a <div xmlns="http://www.w3.org/1999/xhtml">. One
small problem still, but that is another issue: the blue background only appears
on the left and right side, but not on top or bottom. This can be solved by
adding the background style to the <html> element, like:

<html xmlns=... style="background: #006; color: white;">
  <body style="background: #006; color: white;">

Comment 8

14 years ago
... which is not a problem, but a feature. XHTML does not have the infamous
body-fixup rule, which HTML has. Works as designed.
Verifying per reporters comment

Comment 10

13 years ago
*** Bug 296003 has been marked as a duplicate of this bug. ***
You need to log in before you can comment on or make changes to this bug.