Output element in comments

前端 未结 4 1210
谎友^
谎友^ 2020-12-20 12:51

I need to display HTML-element in comments (for example)


I use th

4条回答
  •  一向
    一向 (楼主)
    2020-12-20 13:28

    
    

    As a result:

    
    

    that is the code in the element xsl:comment ignored

    The XSLT 1.0 Spec says:

    It is an error if instantiating the content of xsl:comment creates nodes other than text nodes. An XSLT processor may signal the error; if it does not signal the error, it must recover by ignoring the offending nodes together with their content.

    How do I display an item in the comments?

    It depends what is meant for "display": in a browser:

    <--  -->
    

    may be useful, provided the result of aboveis just simple text (not markup).

    If to "display" means to provide the result as text, then DOE, if allowed by the XSLT processor, may give us the wanted result:

    <-- Some text -->

    Finally, if it is required that what should be inside the "comment" should be markup and it should be displayed as markup, then this is rather challenging. In this case one has to use:

    
    

    and should present every XML lexical item with its desired serialization (i.e. escaped).

    This is how the XPath Visualizer constructs its output.

    Here is a small transformation that demonstrates the first two approaches:

    
     
    
     
          <-- Hello, World -->
    
      <--
       Hello,world! -->
     
    
    

    this transformation, when applied on any XML document (not used), produces:

          <-- Hello, World -->
    
      <--
       Hello,world! -->
    

    Both "comments" may be viewed as comments in a browser, while only the second is presented as comment in free text.

    The third approach (most probably what you want) is illustrated below:

    
     
    
     
      <--  -->
    
     
    
     
      <img src=""
          width="px"
          height="px"/>
     
    
    

    when this transformation is applied on the following XML document:

    
    

    the wanted result is produced:

      <-- 
      <img src="http://example.com/yyy.jpg"
          width="200px"
          height="300px"/>
      -->
    

    viewed in a browser as:

    <-- -->

提交回复
热议问题