使用 FOP "fo:list-item" 导出 PDF 时出错不是 "fo:list-item-body" 的有效子项!
Error exporting PDF with FOP "fo:list-item" is not a valid child of "fo:list-item-body"!
我们在尝试使用 fop 导出 PDF 时遇到错误:
严重:异常
org.apache.fop.apps.FOPException:org.apache.fop.fo.ValidationException:"fo:list-item" 不是 "fo:list-item-body" 的有效子代! (没有可用的上下文信息)
javax.xml.transform.TransformerException:org.apache.fop.fo.ValidationException:"fo:list-item" 不是 "fo:list-item-body" 的有效子代! (没有可用的上下文信息)
据我所知,我们的 XSL 看起来应该 运行。这是 XSL 的摘录。
<xsl:template match="ol" mode="section-body">
<fo:list-block keep-together="always">
<fo:list-item>
<fo:list-item-label>
</fo:list-item-label>
<fo:list-item-body>
<xsl:apply-templates select="li" mode="section-body" />
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</xsl:template>
<xsl:template match="ul" mode="section-body">
<fo:list-block provisional-distance-between-starts="40mm" content-width="2.5in">
<fo:list-item>
<fo:list-item-label>
</fo:list-item-label>
<fo:list-item-body>
<xsl:apply-templates select="li" mode="section-body"/>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</xsl:template>
<xsl:template match="li" mode="section-body">
<xsl:element name="fo:list-item">
<xsl:if test="position() = last()">
</xsl:if>
<fo:list-item-label>
<xsl:choose>
<xsl:when test="parent::ol">
<xsl:element name="fo:block" use-attribute-sets="list-marker-number"><xsl:value-of select="concat(position(),'.')" /></xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="fo:block" use-attribute-sets="list-marker">•</xsl:element>
</xsl:otherwise>
</xsl:choose>
</fo:list-item-label>
<fo:list-item-body>
<xsl:choose>
<xsl:when test="parent::ol">
<xsl:element name="fo:block" use-attribute-sets="list-item-number">
<xsl:apply-templates mode="section-body"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="fo:block">
<xsl:apply-templates mode="section-body"/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</fo:list-item-body>
</xsl:element>
</xsl:template>
您的 ol
和 ul
模板都生成:
<fo:list-block keep-together="always">
<fo:list-item>
<fo:list-item-label>
</fo:list-item-label>
<fo:list-item-body>
<-- Result of processing <li> goes here! -->
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
并且每个 li
生成一个 fo:list-item
,其中包含一个 fo:list-item-label
和一个 fo:list-item-body
。
如果您从 ol
和 ul
模板中删除 fo:list-item
、fo:list-item-label
和 fo:list-item-body
:
<xsl:template match="ol" mode="section-body">
<fo:list-block keep-together="always">
<xsl:apply-templates select="li" mode="section-body" />
</fo:list-block>
</xsl:template>
<xsl:template match="ul" mode="section-body">
<fo:list-block provisional-distance-between-starts="40mm" content-width="2.5in">
<xsl:apply-templates select="li" mode="section-body"/>
</fo:list-block>
</xsl:template>
那么您将不会在 fo:list-item-body
中生成 fo:list-item
。
如果您想尝试在 FOP 之外验证您的 FO,那么我建议 focheck 在 https://github.com/AntennaHouse/focheck
我们在尝试使用 fop 导出 PDF 时遇到错误:
严重:异常 org.apache.fop.apps.FOPException:org.apache.fop.fo.ValidationException:"fo:list-item" 不是 "fo:list-item-body" 的有效子代! (没有可用的上下文信息) javax.xml.transform.TransformerException:org.apache.fop.fo.ValidationException:"fo:list-item" 不是 "fo:list-item-body" 的有效子代! (没有可用的上下文信息)
据我所知,我们的 XSL 看起来应该 运行。这是 XSL 的摘录。
<xsl:template match="ol" mode="section-body">
<fo:list-block keep-together="always">
<fo:list-item>
<fo:list-item-label>
</fo:list-item-label>
<fo:list-item-body>
<xsl:apply-templates select="li" mode="section-body" />
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</xsl:template>
<xsl:template match="ul" mode="section-body">
<fo:list-block provisional-distance-between-starts="40mm" content-width="2.5in">
<fo:list-item>
<fo:list-item-label>
</fo:list-item-label>
<fo:list-item-body>
<xsl:apply-templates select="li" mode="section-body"/>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</xsl:template>
<xsl:template match="li" mode="section-body">
<xsl:element name="fo:list-item">
<xsl:if test="position() = last()">
</xsl:if>
<fo:list-item-label>
<xsl:choose>
<xsl:when test="parent::ol">
<xsl:element name="fo:block" use-attribute-sets="list-marker-number"><xsl:value-of select="concat(position(),'.')" /></xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="fo:block" use-attribute-sets="list-marker">•</xsl:element>
</xsl:otherwise>
</xsl:choose>
</fo:list-item-label>
<fo:list-item-body>
<xsl:choose>
<xsl:when test="parent::ol">
<xsl:element name="fo:block" use-attribute-sets="list-item-number">
<xsl:apply-templates mode="section-body"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="fo:block">
<xsl:apply-templates mode="section-body"/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</fo:list-item-body>
</xsl:element>
</xsl:template>
您的 ol
和 ul
模板都生成:
<fo:list-block keep-together="always">
<fo:list-item>
<fo:list-item-label>
</fo:list-item-label>
<fo:list-item-body>
<-- Result of processing <li> goes here! -->
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
并且每个 li
生成一个 fo:list-item
,其中包含一个 fo:list-item-label
和一个 fo:list-item-body
。
如果您从 ol
和 ul
模板中删除 fo:list-item
、fo:list-item-label
和 fo:list-item-body
:
<xsl:template match="ol" mode="section-body">
<fo:list-block keep-together="always">
<xsl:apply-templates select="li" mode="section-body" />
</fo:list-block>
</xsl:template>
<xsl:template match="ul" mode="section-body">
<fo:list-block provisional-distance-between-starts="40mm" content-width="2.5in">
<xsl:apply-templates select="li" mode="section-body"/>
</fo:list-block>
</xsl:template>
那么您将不会在 fo:list-item-body
中生成 fo:list-item
。
如果您想尝试在 FOP 之外验证您的 FO,那么我建议 focheck 在 https://github.com/AntennaHouse/focheck