How to insert   in XSLT

后端 未结 12 806
后悔当初
后悔当初 2020-12-22 16:48

How can I insert

 

Into an XSLT stylesheet, I keep getting this error:

XML Parsing

相关标签:
12条回答
  • 2020-12-22 17:39

    Try to use

    <xsl:text>&#160;</xsl:text>
    

    But it depends on XSLT processor you are using: the XSLT spec does not require XSLT processors to convert it into "&nbsp;".

    0 讨论(0)
  • 2020-12-22 17:40

    When you use the following (without disable-output-escaping!) you'll get a single non-breaking space:

    <xsl:text>&#160;</xsl:text>

    0 讨论(0)
  • 2020-12-22 17:41

    Use this

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

    edit: Downvoters should probably validate that this works first (it does, and is the most general solution to the problem.)

    0 讨论(0)
  • 2020-12-22 17:42

    In addition to victor hugo's answer it is possible to get all known character references legal in an XSLT file, like this:

    <!DOCTYPE stylesheet [
      <!ENTITY % w3centities-f PUBLIC "-//W3C//ENTITIES Combined Set//EN//XML"
          "http://www.w3.org/2003/entities/2007/w3centities-f.ent">
      %w3centities-f;
    ]>
    ...
    <xsl:text>&amp; &nbsp; &ndash;</xsl:text>
    

    There is also certain difference in the result of this approach as compared to <xsl:text disable-output-escaping="yes"> one. The latter is going to produce string literals like &nbsp; for all kinds of output, even for <xsl:output method="text">, and this may happen to be different from what you might wish... On the contrary, getting entities defined for XSLT template via <!DOCTYPE ... <!ENTITY ... will always produce output consistent with your xsl:output settings.

    And when including all character references, it may be wise to use a local entity resolver to keep the XSLT engine from fetching character entity definitions from the Internet. JAXP or explicit Xalan-J users may need a patch for Xalan-J to use the resolver correctly. See my blog XSLT, entities, Java, Xalan... for patch download and comments.

    0 讨论(0)
  • 2020-12-22 17:46

    Although answer has been already provided by @brabster and others.
    I think more reusable solution would be:

    <xsl:variable name="space">&#160;</xsl:variable>
    ...
    <xsl:value-of select="$space"/>
    
    0 讨论(0)
  • 2020-12-22 17:49

    You might want to add the definition for this entity in the beginning of the file (below xml declaration):

    <!DOCTYPE stylesheet [
    <!ENTITY nbsp  "&#160;" >
    ]>
    

    Also you can add more entities such as Ntilde, Aacute, etc.

    0 讨论(0)
提交回复
热议问题