首页 > 解决方案 > 为什么样式不适用于princexml中的xml

问题描述

我有一些 XML:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="./example.xsl"?>
<article>
    <title>Some title</title>
    <author>Some Author</author>
</article>

和 XSL:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/2001/XMLSchema-instance">
  <xsl:output method="html" />

  <xsl:template match="/">
    <h1>
      <xsl:value-of select="//title"/>
    </h1>
    <h2>
      <xsl:value-of select="//author"/>
    </h2>
  </xsl:template>
</xsl:stylesheet>

当我在浏览器上运行它时,我有这个: 在此处输入图像描述

但是我需要从此 XML 生成 PDF,因此我应该使用princexml,当我运行 prince ./examples/example.xml生成包含以下内容的 pdf 时: 在此处输入图像描述 为什么样式不适用于里面的 xml princexml

标签: xmlxsltprincexml

解决方案


Prince 不支持 XSL,它支持 CSS。请先使用 XSLT 处理器转换 XML,然后将结果传递给 Prince。


推荐阅读