This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Mozilla XML > May 2007 > Unusual behaviour when outputting <img>





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Unusual behaviour when outputting <img>
Matthew Wilson

2007-05-11, 6:56 pm

Recently I have seen some odd behaviour in Mozilla's XSLT processor
(using Firebird 0.7) and was wondering it is a bug.

I have a template as follows to match an "img" element (which is
actually a WML img element) and output an HTML version:

<xsl:template match="img">
<img title="{@alt}">
<xsl:for-each select="@src | @alt | @vspace | @hspace | @align |
@width | @height">
<xsl:copy />
</xsl:for-each>
</img>
</xsl:template>

This was failing to copy any of the attributes in the for-each
element.

This seems to occur if I change the <img> output to <br>, so
presumably it is associated with HTML elements which do not contain
content.

The problem goes away if I remove all the line breaks between the
elements between <img> and </img>.

I am using <xsl:output method="xml"> if it is an issue.

I don't see why whitespace in the stylesheet (even if it is
significant whitespace) should cause this breakage in the XSLT
transformation. Whatever XSLT processor I have installed with my JDK
doesn't exhibit this. Is it a Mozilla bug?
Jonas Sicking

2007-05-11, 6:56 pm

Hi Matthew,

First off, does it work on a recent mozilla build (such as 1.6b or a
recent nightly)?

Are you by any chance using javascript to perform the transformation? Or
are you using an <?xml-stylesheet?> instruction to do the transformation?
If you're using javascript it's a know problem that the mozilla-dom
can't put children into certain elements (such as <img> ) which means
that when the XSLT engine gets the stylesheet it will already be broken.
This problem is being worked on and will be fixed for mozilla 1.7.

Are you creating xhtml by properly putting an
xmlns="http://www.w3.org/1999/xhtml" attribute at the top of the
stylesheet since you're outputting xml? If not then you should either do
that or switch to creating html by removing the xsl:output element and
not having a default namespace.

If it's neither of these problems and you're still experiencing it in a
recent build then please file a bug in bugzilla. There will probably be
workarounds in the meantime, but i'll wait with suggesting anything
until i know more what's going on.

Best Regards,
Jonas Sicking

Matthew Wilson wrote:
> Recently I have seen some odd behaviour in Mozilla's XSLT processor
> (using Firebird 0.7) and was wondering it is a bug.
>
> I have a template as follows to match an "img" element (which is
> actually a WML img element) and output an HTML version:
>
> <xsl:template match="img">
> <img title="{@alt}">
> <xsl:for-each select="@src | @alt | @vspace | @hspace | @align |
> @width | @height">
> <xsl:copy />
> </xsl:for-each>
> </img>
> </xsl:template>
>
> This was failing to copy any of the attributes in the for-each
> element.
>
> This seems to occur if I change the <img> output to <br>, so
> presumably it is associated with HTML elements which do not contain
> content.
>
> The problem goes away if I remove all the line breaks between the
> elements between <img> and </img>.
>
> I am using <xsl:output method="xml"> if it is an issue.
>
> I don't see why whitespace in the stylesheet (even if it is
> significant whitespace) should cause this breakage in the XSLT
> transformation. Whatever XSLT processor I have installed with my JDK
> doesn't exhibit this. Is it a Mozilla bug?


Matthew Wilson

2007-05-11, 6:56 pm

Jonas Sicking <jonas.REMOVE@ME.sicking.cc> wrote in message news:<bu4nvb$f9b3@ripley.netscape.com>...
> Hi Matthew,
>
> First off, does it work on a recent mozilla build (such as 1.6b or a
> recent nightly)?


Haven't tried it yet but will do so later.

> Are you by any chance using javascript to perform the transformation? Or
> are you using an <?xml-stylesheet?> instruction to do the transformation?
> If you're using javascript it's a know problem that the mozilla-dom
> can't put children into certain elements (such as <img> ) which means
> that when the XSLT engine gets the stylesheet it will already be broken.
> This problem is being worked on and will be fixed for mozilla 1.7.


Yes, I'm using Javascript.

Do you know the bug number for this?

> Are you creating xhtml by properly putting an
> xmlns="http://www.w3.org/1999/xhtml" attribute at the top of the
> stylesheet since you're outputting xml? If not then you should either do
> that or switch to creating html by removing the xsl:output element and
> not having a default namespace.


Yes, I'm doing this.

Thanks for your prompt and helpful advice,

Matthew
Jonas Sicking

2007-05-11, 6:56 pm

Matthew Wilson wrote:

> Jonas Sicking <jonas.REMOVE@ME.sicking.cc> wrote in message news:<bu4nvb$f9b3@ripley.netscape.com>...
>
>
>
> Haven't tried it yet but will do so later.


I can tell you right away that it won't work unfortunatly.

>
>
> Yes, I'm using Javascript.
>
> Do you know the bug number for this?


I can't find a bug for this this specific issue, but it'll be fixed soon
as part of bug 195350. Feel free to open a new bug on this specific
issue if you want. And make it depend on bug 195350. In any event i can
almost promice it will work in 1.7 once it's shipped.

In the meantime there are workarounds. First, as you noted you can use
<xsl:element name="img"> instead of <img>.

Second you can switch to creating html rather then xhtml. That will get
around the problem since the elements in your stylesheet will then be in
the null namespace, which mozilla has no problem with nesting any way
you want.

Hope that helps,
Jonas Sicking

Sponsored Links


Copyright 2003 - 2009 forum4designers.com  Software forum  Computer Hardware reviews