Does libxslt have a function to split a document into multiple documents?

It seems libxslt does not support XSLT 2.0 and xsl:result-document. Is there any way to simulate xsl:result-documentusing libxsltor xsltproc?

+5
source share
3 answers

Yes there is, 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>

upon startup as follows:

xsltproc foo.xsl foo.html

will result in this: stdout:

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

also writing this in toc.html:

<html><body><h1>Hello, world!</h1></body></html>
+13
source

If libxslt implements EXSLT , you can use . <exsl:document>

, , XSLT 1.0 .

. , libxslt EXSLT. <exsl:document>.

+3

And here is an example that shows how to use the extension to create an unlimited number of files as you progress through a set of nodes. Again using xsltproc (libxslt)

XML input example:

<clients>
    <client id="ACME1" name="ACME Company 1"/>
    <client id="ACME2" name="ACME Company 2"/>
    <client id="ACME3" name="ACME Company 3"/>
</clients>

XSLT Example:

<?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" indent="yes" encoding="UTF-8" />

<xsl:template match="/">
    <xsl:for-each select="/clients/client">
    <exsl:document href="{@id}.html" method="html">
      <html>
        <body>
          <h1>Company: <xsl:apply-templates select="@name"/></h1>
        </body>
      </html>
    </exsl:document>
    </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

Will create 3 files ACME1.html, ACME2.html, etc.

0
source

All Articles