Using an HTML entity in XSLT (e.g.  )

前端 未结 11 2047
无人及你
无人及你 2020-11-28 07:29

What is the best way to include an html entity in XSLT?


    
    &am         


        
相关标签:
11条回答
  • 2020-11-28 08:02

    It is also possible to extend the approach from 2nd part of aku's answer and get all known character references available, 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>&nbsp;&minus;30&deg;</xsl:text>
    

    There is certain difference in the result as compared to <xsl:text disable-output-escaping="yes"> approach. The latter one 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.

    It may be wise then 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-11-28 08:04

    Now that there's Unicode, it's generally counter-productive to use named character entities. I would recommend using the Unicode character for a non-breaking space instead of an entity, just for that reason. Alternatively, you could use the entity &#160;, instead of the named entity. Using named entities makes your XML dependent on an inline or external DTD.

    0 讨论(0)
  • 2020-11-28 08:05

    this one returns a XsltParseError

    Yes, and the reason for that is that &nbsp; is not a predefined entity in XML or XSLT as it is in HTML.

    You could just use the unicode character which &nbsp; stands for: &#160;

    0 讨论(0)
  • 2020-11-28 08:06

    XSLT only handles the five basic entities by default: lt, gt, apos, quot, and amp. All others need to be defined as @Aku mentions.

    0 讨论(0)
  • 2020-11-28 08:09

    one other possibility to use html entities from within xslt is the following one:

    <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
    
    0 讨论(0)
提交回复
热议问题