使用 xsl fo 在 PDF 文档中创建超链接

Pay*_*l M 1 xslt xsl-fo apache-fop

我正在使用 xsl fo 和 Java 从 XML 生成 PDF。我需要在我的 6 列表的一列中嵌入一个超链接。这是我的代码片段。

    <fo:table-row>
    <xsl:for-each select="./clientMain/hierarchy/link">
    <fo:table-cell border="solid 1px black" text-align="left" font-size="10pt"><fo:block>Hierarchy</fo:block></fo:table-cell>
    <fo:table-cell border="solid 1px black" text-align="left" font-size="9pt">
    <fo:block><a>
    <xsl:attribute name="href"><xsl:value-of select="@link"/></xsl:attribute>
    </a></fo:block>
    <fo:block><xsl:value-of select="@link"/></fo:block></fo:table-cell>
    </xsl:for-each>
    </fo:table-row>
Run Code Online (Sandbox Code Playgroud)

但我的程序失败并出现此错误:

javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: "fo:table-row" is missing child elements. Required content model: (table-cell+) (No context info available)
    at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:718)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2336)
    at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:682)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2336)
    at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:682)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2336)
Run Code Online (Sandbox Code Playgroud)

如果我评论这一行,一切正常。请帮忙 !!!!

Hob*_*bes 5

不是“fo:table-row”缺少子元素错误的解决方案,但是:

查看您的代码,我希望链接不起作用。取而代之的是的<a>标签,使用<fo:basic-link internal-destination="@link" color="blue">

这假设 @link 包含对 PDF 中某个位置的 ID 的引用。

对于外部链接,请使用 <fo:basic-link external-destination="url">