Can I shorten this?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • harryajh

    Can I shorten this?

    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:variabl e name="mandatory "><xslt:tex t disable-output-
    escaping="yes"> &amp;nbsp;:&amp ;nbsp;*</xslt:text></xslt:variable>

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

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

    thanks

    harry
  • Richard Tobin

    #2
    Re: Can I shorten this?

    In article <97ed04c6-f2b0-4642-8be7-79be802d8a03@34 g2000hsf.google groups.com>,
    harryajh <harryajh@yahoo .co.ukwrote:
    >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
    >&#160;) 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 &#160; (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

    Comment

    • Joseph J. Kesselman

      #3
      Re: Can I shorten this?

      harryajh wrote:
      The best way (several articles recommend using &amp;nbsp; instead of
      &#160;)
      Good indication that those articles' authors didn't understand XSLT. Try

      <xslt:variabl e name="mandatory ">&#160;:&#160; </xslt:variable>

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

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

      Comment

      • harryajh

        #4
        Re: Can I shorten this?

        On 23 Apr, 15:29, rich...@cogsci. ed.ac.uk (Richard Tobin) wrote:
        In article <97ed04c6-f2b0-4642-8be7-79be802d8...@34 g2000hsf.google groups.com>,
        >
        harryajh <harry...@yahoo .co.ukwrote:
        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
        &#160;) 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 &#160; (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:variabl e name="mandatory "><xslt:tex t disable-output-
        escaping="yes"> &#160;:&#160 ;*</xslt:text></xslt:variable>

        and using like this -

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

        seems to work well!

        thanks anyway!

        Comment

        • Richard Tobin

          #5
          Re: Can I shorten this?

          In article <8a213e25-8cbc-47c4-bf82-aaec43a06b0a@56 g2000hsm.google groups.com>,
          harryajh <harryajh@yahoo .co.ukwrote:
          >changed to this
          >
          <xslt:variabl e name="mandatory "><xslt:tex t disable-output-
          >escaping="yes" >&#160;:&#160;* </xslt:text></xslt:variable>
          Why are you using disable-output-escaping at all? What's wrong with:

          <xsl:variable name="mandatory ">&#160;:&#160; *</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

          Comment

          • Joseph J. Kesselman

            #6
            Re: Can I shorten this?

            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.

            Comment

            Working...