How to preserve Empty XML Tags after XSLT - prevent collapsing them from to

后端 未结 10 2613
不思量自难忘°
不思量自难忘° 2020-12-18 22:31

Say I have a very simple XML with an empty tag \'B\':


  foo
  
  bar



        
相关标签:
10条回答
  • 2020-12-18 23:08

    No. The 2 are syntactically identical, so you shouldn't have to worry

    0 讨论(0)
  • 2020-12-18 23:10

    Try this:

    <script type="..." src="...">&#160;</script>
    

    Your HTML output will be:

    <script type="..." src="..."> </script>
    

    The &#160; prevents the collapsing but translates to a blank space. It's worked for me in the past.

    0 讨论(0)
  • 2020-12-18 23:14
    <xsl:text disable-output-escaping="yes">
    <![CDATA[<div></div>]]>
    </xsl:text>
    

    This works fine with C#'s XslCompiledTransform class with .Net 2.0, but may very well fail almost anywhere else. Do not use unless you are programmatically doing the transofrm yourself; it is not portable at all.

    0 讨论(0)
  • 2020-12-18 23:15

    It should not be a problem if it is or . However if you are using another tool which expects empty XML tags as way only, then you have a problem. A not very elegant way to do this will be adding a space between staring and ending 'B' tags through XSLT code.

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