Can I shorten this?

Discussion in 'XML' started by harryajh, Apr 23, 2008.

  1. harryajh

    harryajh Guest

    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
     
    harryajh, Apr 23, 2008
    #1
    1. Advertising

  2. In article <>,
    harryajh <> wrote:
    >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
    --
    :wq
     
    Richard Tobin, Apr 23, 2008
    #2
    1. Advertising

  3. harryajh wrote:
    > 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>
     
    Joseph J. Kesselman, Apr 23, 2008
    #3
  4. harryajh

    harryajh Guest

    On 23 Apr, 15:29, (Richard Tobin) wrote:
    > In article <>,
    >
    > harryajh <> wrote:
    > >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
    > --
    > :wq


    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!
     
    harryajh, Apr 23, 2008
    #4
  5. In article <>,
    harryajh <> wrote:

    >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
    --
    :wq
     
    Richard Tobin, Apr 23, 2008
    #5
  6. > 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.
     
    Joseph J. Kesselman, Apr 23, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kenneth Keeley

    Shorten a SQL VarChar result.

    Kenneth Keeley, Oct 28, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    695
    Scott Mitchell [MVP]
    Oct 28, 2004
  2. =?Utf-8?B?V2ViIFJlc3BvbnNlIFRpbWU=?=

    How can I shorten this time?

    =?Utf-8?B?V2ViIFJlc3BvbnNlIFRpbWU=?=, Oct 28, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    346
    Scott Allen
    Oct 28, 2004
  3. Crispy
    Replies:
    3
    Views:
    682
    sinclar sodersas
    Jul 12, 2003
  4. Francois Grieu

    Can you shorten this macro?

    Francois Grieu, Apr 5, 2009, in forum: C Programming
    Replies:
    4
    Views:
    348
    Francois Grieu
    Apr 5, 2009
  5. nephish
    Replies:
    7
    Views:
    117
    nephish
    Nov 11, 2006
Loading...

Share This Page