Re: [xsl] Empty object

Subject: Re: [xsl] Empty object
From: "Mike Haarman" <mhaarman@xxxxxxxxxxxxxxxxxx>
Date: Wed, 28 Jan 2004 14:34:47 -0600
> I have attached my xml input file and my stylesheet I am still getting
> in my output <OBJECT> </OBJECT> instead of <OBJECT>&nbsp;</OBJECT>.

Scott,

I think what you are missing is the role of an entity as a placeholder,
a name for, something to be textually substituted where the reference
appears in content.  Thus, your & nbsp; *is* appearing in your output as
the character you have defined it to be: a non-breaking space, i.e. &
#xa0; or & #160; (spaces added to prevent munging).

But, since you are no longer referring to an entity in your source
document, the DOCTYPE declaration is no longer necessary.  Or the
content of OBJECT below was changed to facilitate debugging and you
really are receiving & nbsp; in your sources, in which case it is
required.

There is nothing magic about & nbsp; for your HTML output.  The
character designated 160 functions as you expect when rendered by the
browser, holding space, etc.  Indeed, & nbsp; is merely a predefined
entity for HTML which is resolved to the character when processed by a
client browser.  You don't need to make this entity reference appear in
your output for it to function properly.

> Obvisouly my OBJECT template is not properly copying my element and
> character contents over properly.

Your OBJECT template looks fine; however, it could be rewritten to be
more idiomatically XSL and rather more succinct.  Rather than a for-each
and a test against a hard list of attributes to process, you can
apply-templates and select any available attributes, or if only those
particular attributes interest you, use select="ALIGN | STYLE | WIDTH |
HEIGHT | NAME | TYPE | VALIGN | COLSPAN | ROWSPAN".  Using a mode will
prevent stepping on any default templates.

The template for processing attributes could look like this:

<xsl:template match="@*" mode="passthrough">
   <xsl:attribute name="translate(name(.),ABCDEFGHIJKLMNOPQRSTUVWXYZ,
abcdefghijklmnopqrstuvwxyz)">
      <xsl:value-of select="."/>
   </xsl:attribute>
</xsl:template



If you absolutely, positively, have to see the entity & nbsp; in your
output, test the text() content of the OBJECT node for & #160; and
output literally:

<xsl:text>&amp;nbsp;</xsl:text>

This entity is already defined for XHTML, I believe.

hth,

Mike


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread