How to Embed XSL into XML

I am looking for a solution to embed XSL into XML so there is only 1 XML file that is sent to the browser. I tried the solution proposed by Dimitre Novatchev here: Embed xsl into an XML file

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes"/> <xsl:variable name="vEmbDoc"> <doc> <head></head> <body> <para id="foo">Hello I am foo</para> </body> </doc> </xsl:variable> <xsl:template match="para"> <h1><xsl:value-of select="."/></h1> </xsl:template> <xsl:template match="xsl:template"/></xsl:stylesheet>

The problem is that with this solution I can not find a way to include style element inside the head. Seems like in the proposed solution head and body tags do not have any effect since the browser will add them automatically during parsing and the solution works even without having those tags included.

So the question is: How to include style element in the head in the above mentioned solution that will look like this:

<head><style>body {font-size:10pt;padding:20pt} </style></head>


<strong>This XML document</strong>:

<?xml-stylesheet type="text/xsl" href="myEmbedded.xml"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl"> <xsl:output omit-xml-declaration="yes"/> <xsl:variable name="vEmbDoc"> <doc> <head> <style>body {font-size:10pt;padding:20pt}</style> </head> <body> <para id="foo">Hello I am foo</para> </body> </doc> </xsl:variable> <xsl:template match="para"> <h1><xsl:value-of select="."/></h1> </xsl:template> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="doc"> <html> <xsl:apply-templates/> </html> </xsl:template> <xsl:template match="xsl:template"/> <xsl:template match="xsl:*"> <xsl:apply-templates/> </xsl:template> </xsl:stylesheet>

<strong>contains an XSLT stylesheet. The starting PI instructs the browser to apply this stylesheet on itself</strong>.

<strong>The transformation thus specified, produces the wanted result</strong>:

<html> <head xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <style>body {font-size:10pt;padding:20pt}</style> </head> <body xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <h1>Hello I am foo</h1> </body> </html>


  • Swift leave out .self to invoke a function which needs metatype?
  • Merging rows with shared information
  • xslt - referencing the output result of the previous template
  • undefined reference error due to use of static variables [duplicate]
  • Excel passing a range into a function
  • What is the likely cause of a net::ERR_CONNECTION_ABORTED when uploading a file to Spring
  • What Makes These Two Array Adds Different?
  • Doctrine/Symfony entity generator and generating entity from one table
  • Xamarin Android | Layout style
  • Setting the run time properties on SpringApplicationBuilder()
  • Why isn't obj.style.left = “200px”; working in this code?
  • Tell Git to stop prompting me for conflicts when none really exist?
  • Enabling DTD support in Sql Server
  • NUnit 3.0 TestCase const custom object arguments
  • where do I find the xml.dom python package for the python-2.6.0-8.9.28 and I have a suse/x86_64 vers
  • How to get current document uri in XSLT?
  • saving file generated by TCPDF
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • Alternative To body {overflow:scroll;} That Will Prevent Page Jostling/Wriggling?
  • Xcode 4 NSLog Macro link in Xcode 3
  • How to attach a node.js readable stream to a Sendgrid email?
  • Play WS (2.2.1): post/put large request
  • Jquery UI tool tip close icon
  • PostgreSQL Query without WHERE only ORDER BY and LIMIT doesn't use index
  • Display issues when we change from one jquery mobile page to another in firefox
  • Modifying destination and filename of gulp-svg-sprite
  • Deserializing XML into class C#
  • JSON with duplicate key names losing information when parsed
  • htaccess rewriting URLs with multiple forward slashes
  • Weird JavaScript statement, what does it mean?
  • How do you troubleshoot character encoding problems?
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • Is there a mandatory requirement to switch app.yaml?
  • How to format a variable of double type
  • python draw pie shapes with colour filled
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?