Can I shorten this?

H

harryajh

I need to output some standard text (" : *" i.e. space colon space
asterisk) in loads of places in my XSLT document which outputs XHTML
in XML format.

The best way (several articles recommend using   instead of
 ) I've found to do this is using as follows -

<xslt:text disable-output-escaping="yes">&amp;nbsp;:&amp;nbsp;*</
xslt:text>

as this is quite long, is there anyway that I can define it as a sort
of global constant?

I've tried this -

<xslt:variable name="mandatory"><xslt:text disable-output-
escaping="yes">&amp;nbsp;:&amp;nbsp;*</xslt:text></xslt:variable>

and then - <xslt:value-of select="$mandatory"/>

but this produces "&nbsp;:&nbsp;*"

thanks

harry
 
R

Richard Tobin

I need to output some standard text (" : *" i.e. space colon space
asterisk) in loads of places in my XSLT document which outputs XHTML
in XML format.

I'm a bit confused here. You say you need to output spaces, but then
you start talking about non-breaking spaces:
The best way (several articles recommend using &amp;nbsp; instead of
 ) I've found to do this is using as follows -

And I'm not clear about this: I can see you might want to produce
&nbsp; instead of   (though they should be equivalent, and the
numeric constant means you don't need a DTD to parse it as XML), but
why would you want "&amp;nbsp;"? Or has your news program munged
the escaping?

-- Richard
 
J

Joseph J. Kesselman

harryajh said:
The best way (several articles recommend using &amp;nbsp; instead of
 )

Good indication that those articles' authors didn't understand XSLT. Try

<xslt:variable name="mandatory"> : </xslt:variable>

or, if you don't explicitly need a non-breaking space character,

<xslt:variable name="mandatory"> : </xslt:variable>
 
H

harryajh

I'm a bit confused here. You say you need to output spaces, but then
you start talking about non-breaking spaces:


And I'm not clear about this: I can see you might want to produce
&nbsp; instead of   (though they should be equivalent, and the
numeric constant means you don't need a DTD to parse it as XML), but
why would you want "&amp;nbsp;"? Or has your news program munged
the escaping?

-- Richard

sorry for my awful wording, when I said "space" I did indeed mean a
&nbsp;

changed to this

<xslt:variable name="mandatory"><xslt:text disable-output-
escaping="yes"> : *</xslt:text></xslt:variable>

and using like this -

<xslt:value-of select="$mandatory"/>

seems to work well!

thanks anyway!
 
R

Richard Tobin

harryajh said:
changed to this

<xslt:variable name="mandatory"><xslt:text disable-output-
escaping="yes"> : *</xslt:text></xslt:variable>

Why are you using disable-output-escaping at all? What's wrong with:

<xsl:variable name="mandatory"> : *</xsl:variable>

If the problem is that you don't like the output having literal
non-breaking spaces, you could specify ascii as the output encoding.

-- Richard
 
J

Joseph J. Kesselman

Why are you using disable-output-escaping at all?

Because the references he had looked at were trying to manually
construct the character sequence '&nbsp;. Which was Very Bad Practice,
as we all agreed.
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top