libxslt 是否具有将一个文档拆分为多个文档的功能?

发布于 2024-09-08 08:21:43 字数 152 浏览 1 评论 0原文

看起来 libxslt 不支持 XSLT 2.0 和 xsl:result-document。有没有办法使用libxsltxsltproc来模拟xsl:result-document

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

满栀 2024-09-15 08:21:43

是的,有,使用 exsl:document。一个简单的例子:

==== 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>

将此作为输入:

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

当像这样运行时:

xsltproc foo.xsl foo.html

会将其生成到 stdout:

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

同时还将其写入 toc.html

<html><body><h1>Hello, world!</h1></body></html>

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>
浅听莫相离 2024-09-15 08:21:43

如果 libxslt 实现 EXSLT,那么您可以使用 扩展元素。

如果没有,那么您必须编写自己的扩展函数,因为 XSLT 1.0 不支持创建多个结果文档。

更新:如此注释,libxslt 实现了 EXSLT。只需抓住它并使用

If libxslt implements EXSLT, then you could use the <exsl:document> extension element.

If not, then you have to write your own extension functions, because XSLT 1.0 does not support creating multiple result documents.

Update: As confirmed in this comment, libxslt implements EXSLT. Just grab it and use <exsl:document> .

输什么也不输骨气 2024-09-15 08:21:43

下面的示例展示了如何使用扩展在遍历节点集时创建无限数量的文件。再次使用 xsltproc (libxslt)

示例 XML 输入:

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

示例 XSLT:

<?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>

将生成 3 个文件 ACME1.html、ACME2.html 等。

And here is an example that shows how to use the extension to create an unlimited number of files as a nodeset is traversed. Again, using xsltproc (libxslt)

Sample XML Input:

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

Sample XSLT:

<?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 produce 3 files ACME1.html, ACME2.html, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文