Search code examples
xmlxsltxsl-fo

How to create hyperlink in fo:block-container and fo:table?


I use xslt to build PDF from XML. In pdf-file I need to create hyperlinks in some areas like entire table or some area (block-container with background color). I tried to use <fo:basic-link external-destination="http://...">, but have no success. It works for text, but not for block-container and table. If someone knows how to do it, please help. I use Saxon and Apache FOP, just in case.


Solution

  • fo:basic-link (https://www.w3.org/TR/xsl11/#fo_basic-link) is your only option for making links. As you have found, fo:basic-link is an 'inline' FO. See the classifications of %block; and %inline; FOs at https://www.w3.org/TR/xsl11/#d0e6532

    However, fo:basic-link is defined to allow %block; content, so you should be able to put an fo:table inside an fo:basic-link. I.e., use nesting like:

    fo:block
      fo:basic-link
        fo:table
    

    If that doesn't work, however, you could put your fo:table inside an fo:inline-container, since that's an 'inline' FO and also allowed inside fo:basic-link. You'd end up with a nesting structure like:

    fo:block
      fo:basic-link
        fo:inline-container
          fo:table
    

    Whether your formatter will do the right thing is a different question, but both ways should work.