Creating a Self-Contained HTML Transformation


You want to package XML data, as well as a stylesheet for converting it to HTML, into a single file.


This recipe assumes you have a browser that supports client-side XSLT transformations (IE 6.0, IE 5.x + MSXML 3.0, Netscape Navigator 6.0, etc.):

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="application/xml" href="selfcontained.xsl"?>
<xsl:stylesheet version="1.0" xmlns:xsl=""
<portfolio xmlns="">
<xsl:output method="html" />
  <xsl:attribute-set name="gain-loss-font">
    <xsl:attribute name="color">
        <xsl:when test="(pf:current - pf:paid) * pf:qty >= 0">black</xsl:when>
<xsl:template match="xsl:stylesheet">
               <xsl:apply-templates select="pf:portfolio"/>
               </xsl:template> <xsl:template match="pf:portfolio"> <html> <head> <title>My ...

Get XSLT Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.