Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does libxslt have a feature for splitting a document into multiple documents?

Tags:

xml

xslt

libxslt

Looks like libxslt does not support XSLT 2.0, and xsl:result-document. Is there a way to mimic xsl:result-document using libxslt, or xsltproc?

like image 447
Behrang Avatar asked Jul 02 '10 17:07

Behrang


1 Answers

Yes, there is, using exsl:document. A simple example:

==== foo.xsl ====
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
                xmlns:exsl="http://exslt.org/common"
                extension-element-prefixes="exsl">
  <xsl:output method="html"/>
  <xsl:template match="/">
    <exsl:document href="toc.html" method="html">
      <html>
        <body>
          <xsl:apply-templates select=".//h1"/>
        </body>
      </html>
    </exsl:document>
    <xsl:apply-templates/>
  </xsl:template>
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

taking this as input:

==== foo.html ====
<html>
  <body>
    <h1>Hello, world!</h1>
    <p>Some longwinded text follows.</p>
  </body>
</html>

when run like this:

xsltproc foo.xsl foo.html

will yield this to stdout:

<html>
  <body>
    <h1>Hello, world!</h1>
    <p>Some longwinded text follows.</p>
  </body>
</html>

while also writing this to toc.html:

<html><body><h1>Hello, world!</h1></body></html>
like image 144
Owen S. Avatar answered Sep 28 '22 03:09

Owen S.