Skip to content

Instantly share code, notes, and snippets.

@breezhang
Created March 30, 2012 11:36
Show Gist options
  • Save breezhang/2250964 to your computer and use it in GitHub Desktop.
Save breezhang/2250964 to your computer and use it in GitHub Desktop.
XSLT import css

Rick Roen wrote:

Hi

<style type="text/css"> @import "salesdoc.css"; </style>

This (the "@import") is plain text for XSLT. You can use unparsed-text() to read a file as a string:

~> cat import-css.xsl
<xsl:transform
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="2.0">

  <xsl:output omit-xml-declaration="yes"/>

  <xsl:template match="/">
    <style type="text/css">
      <xsl:text>&#10;</xsl:text>
      <xsl:copy-of
          select="unparsed-text('import-css.css')"/>
    </style>
  </xsl:template>

</xsl:transform>

~> cat import-css.css
body {
    color: #333;
}

~> saxon import-css.xsl import-css.xsl
<style type="text/css">
body {
    color: #333;
}
</style>

Regards,

--drkm

@breezhang
Copy link
Author

XSLT 2.0 provides the unparsed-text() function to read documents via URL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment