self-closing tags

D

David Schwartz

My xsl includes image tags as follows:

<img src="../images/u.gif" width="16" height="16" alt="Back to top"
border="0"/>

Yet, after processing, the img tag is no longer self-closing so it's
not well-formed.

Can someone tell me what's going on and how to fix?

FYI, I'm using XALAN v.2.7.0

TIA,
David
 
M

Martin Honnen

David said:
My xsl includes image tags as follows:

<img src="../images/u.gif" width="16" height="16" alt="Back to top"
border="0"/>

Yet, after processing, the img tag is no longer self-closing so it's
not well-formed.

"well-formed" is defined for XML and with XML
<img />
as well as
<img/>
as well as
<img></img>
_is_ well-formed.

If you want to generate HTML with your stylesheet then you want
<img>
and that is achieved by using
<xsl:eek:utput method="html"/>
and by making sure your result elements are in no namespace.
 
D

David Schwartz

"well-formed" is defined for XML and with XML
<img />
as well as
<img/>
as well as
<img></img>
_is_ well-formed.

If you want to generate HTML with your stylesheet then you want
<img>
and that is achieved by using
<xsl:eek:utput method="html"/>
and by making sure your result elements are in no namespace.

I am using <xsl:eek:utput method="html"/>. Also, I'm looking for xhmtl so
<img> by itself won't do and, as I understand it anyway, not well-
formed in that context. Any thoughts what might be going on?

My result elements are not in a namespace. FWIW, here are the
stylesheet and output elements (I use the redirect to produce the
output files):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform" xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
extension-element-prefixes="redirect">
<!-- <xsl:eek:utput method="html" version="4.0" indent="yes"
encoding="ISO-8859-1"/> -->
<xsl:eek:utput method="xml" omit-xml-declaration="yes" version="4.0"
indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
encoding="ISO-8859-1"/>


Thanks for the help.

David
 
D

David Carlisle

David said:
I am using <xsl:eek:utput method="html"/>. Also, I'm looking for xhmtl so
<img> by itself won't do and, as I understand it anyway, not well-
formed in that context. Any thoughts what might be going on?

specifying method="html" tells the xslt system that you do not want xml
syntax, you want html syntax, so specify method="xml" if that's what you
want.
My result elements are not in a namespace. FWIW, here are the
stylesheet and output elements (I use the redirect to produce the
output files):

If the result elements are not in a namespace then they are not xhtml,
whatever syntax is used for empty elements, so add
xmlns="http://www.w3.org/1999/xhtml"
to your xsl:stylesheet element.
This will also have the effect of making the default serialisation xml
as the html serialisation the default, ashtml is only the default output
method if the top level element is html in no namespace.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform" xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
extension-element-prefixes="redirect">
<!-- <xsl:eek:utput method="html" version="4.0" indent="yes"
encoding="ISO-8859-1"/> -->
<xsl:eek:utput method="xml" omit-xml-declaration="yes" version="4.0"
indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
encoding="ISO-8859-1"/>


Thanks for the help.

David

David
 
D

David Schwartz

I added the namespace attribute as you suggested. Sure enough, the
image tags are self-closing now. However, now every resulting element
has the following: div xmlns=""

David
 
D

David Carlisle

David said:
I added the namespace attribute as you suggested. Sure enough, the
image tags are self-closing now. However, now every resulting element
has the following: div xmlns=""

David

That means that you have generated the div in no namespace instead of
the xhtml namespace. If you have declared the xhtml namespace on
xsl:stylesheet then elements created in the stylesheet will be xhtml
(unless you work hard to stop that) so perhaps these div elements have
been copied from an input document?
If the input is in no-namespace and you want to generate elements in the
xhtml namepsace, you don't want to copy with xsl:copy or xsl:copy-of you
want to generate an element in the (new) default namespace but wth the
same local name as before, so don't use
<xsl:copy>
use
<xsl:element name="{local-name()}">

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top