XSL / XML: HOw to place html tags in an xml document so that they display

I am trying to replace tags as follows:

<node><br></node> -- >  <node>&lt;br&gt;</node>

Unfortunately, when xsl parses the xml file I actually get   

<br>

displayed on the page, not displayed as markup.

+3
source share
4 answers

HTML is not XML, although they look very similar; There are four things that are valid in HTML that you cannot do with XML, all of which can be modified to meet XML requirements:

  • Unclosed tags as you discovered. Just replace them with the closed version <br>on <br/>, etc.
  • Attributes without values, e.g. c <input type="checkbox" checked>. Just assign them a value with the same name as the attribute, i.e. <input type="checkbox" checked="checked" />.
  • - . , HTML, <b>A<i>B</b>C</i>, , C B , . XML-, <b>A<i>B</i></b><i>C</i> <b>A</b><i><b>B</b>C</i>.
  • . &lt;, &gt;, &amp;, &quot;, &apos; unicode (, &#160;/&#xA0;) XML. &nbsp; &oslash; - . , , <!ENTITY nbsp "&#160;">.

XSLT HTML , XML.

, HTML, XML , XML, .

<br> &lt;br&gt; TEXT, html, , xml.

+1

html, . html xml, xsl.

XML:

<Data>
  <!--
  <div>
    not well-formed xml<br>
  </div>
 -->
</Data>

XSL:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:template match="Data">
    <html>
      <body>
        <xsl:value-of disable-output-escaping="yes" select="comment()"/>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="text() | @*">
  </xsl:template>
</xsl:stylesheet>

<html>
  <body>
    <div>
     not well-formed xml<br>
    </div>
  </body>
</html>
+1

<br/> XSLT, as-is.

0

, :

<node><br></node>

XML- XSLT 1.0.

:

<node><br/></node>

<br/> "as-is" - .

:

This conversion is :

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="node()|@*">
  <xsl:copy>
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
 </xsl:template>

 <xsl:template match="nodes">
  <html>
   <xsl:apply-templates/>
  </html>
 </xsl:template>

 <xsl:template match="node">
  <p>
   <xsl:apply-templates/>
  </p>
 </xsl:template>
</xsl:stylesheet>

when applied to this XML document :

<nodes>
 <node>
 1 <br/>
 2 <br/>
 3 <br/>
 </node>
</nodes>

produces

<html>
   <p>
      1 <br>
      2 <br>
      3 <br></p>
</html>

, and this is displayed by the browser as :

 

    1
    2
    3

0
source

All Articles