使用 XSL:FO 从 XML 生成 PDF.将超链接内容从 XML 转换为 PDF

问题描述:

如何使用 XSL:FO 将以下包含超链接标签的 XML 转换为 PDF

How to transform the below XML that contains the hyperlink tag to PDF using XSL:FO

    <paragraphs>
     <paragraph>ahsbdgdgdg<a href="https://aaaa.com/xsd &did=jsjsj">Test</a>
     </paragraph>
    </paragraphs>

Use fo:basic-link (https://www.w3.org/TR/xsl11/#fo_basic-link) 并将 URI 放入 external-destination(https://www.w3.org/TR/xsl11/#external-destination):

Use fo:basic-link (https://www.w3.org/TR/xsl11/#fo_basic-link) and put the URI in external-destination (https://www.w3.org/TR/xsl11/#external-destination):

<fo:basic-link
  external-destination="url(https://aaaa.com/xsd%20&amp;did=jsjsj)">test</fo:basic-link>

URI 必须是格式良好的 XML,因此示例中的 & 必须是 XML 中的 &.

The URI has to be well-formed XML, so the & in your example has to be &amp; in your XML.

您是否需要将空格转义为 %20 可能取决于您使用的格式化程序.如果您使用的是 XSLT 2.0 或 XSLT 3.0,那么您将拥有可用于转义 URI 的内置函数.

Whether or not you need to escape the space as %20 possibly depends on which formatter you are using. If you were using XSLT 2.0 or XSLT 3.0, you would have built-in functions available to you for escaping the URI.

XSL 1.1 Recommendation 说您需要在 URI 之前和之后使用 url(),但可能大多数格式化程序会让您忽略它.

The XSL 1.1 Recommendation says that you need url( and ) before and after the URI, but probably most formatters will let you omit that.