Skip to content Skip to sidebar Skip to footer

Is It Possible To Embed Xml Xsl Transformed Into A Html In An Inline Matter

I am wondering if there is possible such situation where I can place inline xml linked with xsl into the body of html, like: text

Solution 1:

As Michael Kay suggested, you can embed the XML in XHTML and apply the stylesheet to the entire document. Then you can apply an XSL transformation to the entire document, applying the identity transform to all HTML elements and specific templates to the embedded non-HTML elements.

Here is an example:

Input XHTML

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="ie8fix.xsl"?><!DOCTYPE htmlSYSTEM"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><title>test</title></head><body>
    text
    <articlesxmlns=""><articletitle="title"/></articles>
    text
  </body></html>

XSLT

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns="http://www.w3.org/1999/xhtml"><xsl:templatematch="node()|@*"><xsl:copy><xsl:apply-templatesselect="node()|@*"/></xsl:copy></xsl:template><xsl:templatematch="articles"><divclass="articles"><h1>articles</h1><xsl:apply-templatesselect="article"mode="transform"/></div></xsl:template><xsl:templatematch="article"mode="transform"><article><!-- HTML5 article element --><h2><xsl:value-ofselect="@title"/></h2><xsl:apply-templatesselect="node()"mode="transform"/></article></xsl:template></xsl:stylesheet>

Output XHTML

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="ie8fix.xsl"?><htmlxmlns="http://www.w3.org/1999/xhtml"><head><title>test</title></head><body>
    text
    <divclass="articles"><h1>articles</h1><article><h2>title</h2></article></div>
    text
  </body></html>

Another option would be to transform the XML after loading the page using JavaScript and XSLTProcessor.

Solution 2:

See section 2.4 of

http://www.w3.org/TR/2012/NOTE-html-xml-tf-report-20120209/

The two approaches suggested there are

(a) Put the XML inside a script element

(b) Use XHTML.

Direct nesting of XML inside the HTML as in your example is not advised because the HTML parser will treat the XML as bad HTML, and try to repair it.

Post a Comment for "Is It Possible To Embed Xml Xsl Transformed Into A Html In An Inline Matter"