create hyper links dynamically when transforming xml to xsl-fo using xlst?

允我心安 提交于 2019-12-02 13:58:37

To display a link in XSL-FO, use fo:basic-link. See the relevant part of the specification for details.

This creates a simple, clickable link without any formatting otherwise. That is, the format is inherited from the surrounding block element. So, if your links should be underlined or shown in blue, you have to specify this explicitly. For instance, by using a fo:inline element.

Now, in terms of XSLT code, if you encounter a elements:

<xsl:template match="a">
 <fo:block><!--This is the heading block-->

Test whether there is a href attribute or not:

  <xsl:choose>
    <xsl:when test="@href">
      <fo:basic-link>
        <xsl:attribute name="external-destination">
          <xsl:value-of select="@href"/>
        </xsl:attribute>
        <xsl:value-of select="."/>
      </fo:basic-link>
    </xsl:when>

On the other hand, if there is no such attribute:

    <xsl:otherwise>
      <xsl:value-of select="."/>
    </xsl:otherwise>
  </xsl:choose>
 </fo:block>

</xsl:template>

Basic links can have either an external or internal destination. The latter is used to refer to specific chapters from the table of contents, for example.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!