最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】去掉docbook中输出的pdf中,除了带链接的文字之外的那个链接地址

Docbook crifan 2161浏览 0评论

【问题】

docbook中,对于这样的xml源码:

<para>本文章遵从:<ulink url="http://creativecommons.org/licenses/by-nc/2.5/cn/">署名-非商业性使用 2.5 中国大陆(CC BY-NC 2.5)</ulink></para>

生成的html是这样的:

html仅显示带链接的文字

这样的是我所要的效果,即带链接的文字,即可。

而生成的pdf中,却显示是这样的:

文字除了自带链接 还显示地址

即,除了带链接的文字之外,还多余的显示出对应的链接地址,这个不是我所想要的,所以希望把pdf中多余显示出来的链接地址去掉。

【解决过程】

1.推断到,这些输入方面的内容控制,应该是对应的xls中控制的,所以就去到xsl中找对应的xlink方面的配置。

最后终于在xref中找到了:

<xsl:template match="d:ulink" name="ulink">
  <xsl:param name="url" select="@url"/>

  <xsl:variable name ="ulink.url">
    <xsl:call-template name="fo-external-image">
      <xsl:with-param name="filename" select="$url"/>
    </xsl:call-template>
  </xsl:variable>

  <fo:basic-link xsl:use-attribute-sets="xref.properties"
                 external-destination="{$ulink.url}">
    <xsl:choose>
      <xsl:when test="count(child::node())=0 or (string(.) = $url)">
        <xsl:call-template name="hyphenate-url">
          <xsl:with-param name="url" select="$url"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
  </fo:basic-link>
  <!-- * Call the template for determining whether the URL for this -->
  <!-- * hyperlink is displayed, and how to display it (either inline or -->
  <!-- * as a numbered footnote). -->
  <xsl:call-template name="hyperlink.url.display">
    <xsl:with-param name="url" select="$url"/>
    <xsl:with-param name="ulink.url" select="$ulink.url"/>
  </xsl:call-template>
</xsl:template>

<xsl:template name="hyperlink.url.display">
  <!-- * This template is called for all external hyperlinks (ulinks and -->
  <!-- * for all simple xlinks); it determines whether the URL for the -->
  <!-- * hyperlink is displayed, and how to display it (either inline or -->
  <!-- * as a numbered footnote). -->
  <xsl:param name="url"/>
  <xsl:param name="ulink.url">
    <!-- * ulink.url is just the value of the URL wrapped in 'url(...)' -->
    <xsl:call-template name="fo-external-image">
      <xsl:with-param name="filename" select="$url"/>
    </xsl:call-template>
  </xsl:param>

  <xsl:if test="count(child::node()) != 0
                and string(.) != $url
                and $ulink.show != 0">
    <!-- * Display the URL for this hyperlink only if it is non-empty, -->
    <!-- * and the value of its content is not a URL that is the same as -->
    <!-- * URL it links to, and if ulink.show is non-zero. -->
    <xsl:choose>
      <xsl:when test="$ulink.footnotes != 0 and not(ancestor::d:footnote)">
        <!-- * ulink.show and ulink.footnote are both non-zero; that -->
        <!-- * means we display the URL as a footnote (instead of inline) -->
        <fo:footnote>
          <xsl:call-template name="ulink.footnote.number"/>
          <fo:footnote-body xsl:use-attribute-sets="footnote.properties">
            <fo:block>
              <xsl:call-template name="ulink.footnote.number"/>
              <xsl:text> </xsl:text>
              <fo:basic-link external-destination="{$ulink.url}">
                <xsl:value-of select="$url"/>
              </fo:basic-link>
            </fo:block>
          </fo:footnote-body>
        </fo:footnote>
      </xsl:when>
      <xsl:otherwise>
        <!-- * ulink.show is non-zero, but ulink.footnote is not; that -->
        <!-- * means we display the URL inline -->
        <fo:inline hyphenate="false">
          <!-- * put square brackets around the URL -->
          <xsl:text> [</xsl:text>
          <fo:basic-link external-destination="{$ulink.url}">
            <xsl:call-template name="hyphenate-url">
              <xsl:with-param name="url" select="$url"/>
            </xsl:call-template>
          </fo:basic-link>
          <xsl:text>]</xsl:text>
        </fo:inline>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:if>

</xsl:template>

2.找到了相关配置,但是却对于上述这么多内容,无从下手,不知道如何修改才能把对应的地址不显示。

不过后来看到了上面的url是否显示,是通过ulink.show来控制的。

然后就去找ulink.show,是在哪里配置的。结果xls文件中没有找到相关的配置。

3.然后就去网上找ulink.show,然后找到了这里:

ulink.show – Miscellaneous

参考其内容,本来以为是要把其中的:

<xsl:param name="ulink.show" select="1"></xsl:param>

写如到对应的xls或xml中,不过后来看到了xsl:param这个字眼,突然想到,估计也是类似之前使用xsltproc时候所用到的,通过stringparam传入进去的参数:

xsltproc.exe --stringparam section.autolabel 1 --stringparam section.label.includes.component.label 1 --stringparam bibliography.numbered 1 --xinclude -o /cygdrive/e/Dev_Root/docbook/dev/src/docbook/books/VBR/output/fo/MPEG_VBR.fo /usr/share/sgml/docbook/xsl-ns-stylesheets/fo/docbook_fo_crl_yahei.xsl /cygdrive/e/Dev_Root/docbook/dev/src/docbook/books/VBR/src/MPEG_VBR.xml

所以,就用下面的代码,去试试:

xsltproc.exe --stringparam section.autolabel 1 --stringparam section.label.includes.component.label 1 --stringparam bibliography.numbered 1 --stringparam ulink.show 0 --xinclude -o /cygdrive/e/Dev_Root/docbook/dev/src/docbook/books/VBR/output/fo/MPEG_VBR.fo /usr/share/sgml/docbook/xsl-ns-stylesheets/fo/docbook_fo_crl_yahei.xsl /cygdrive/e/Dev_Root/docbook/dev/src/docbook/books/VBR/src/MPEG_VBR.xml

然后再用fop将fo转换为pdf,结果就实现了所需要的效果了:

去掉了url显示

【总结】

想要输入的pdf中的带链接的文字后面的那个url地址不显示,可以通过给xsltproc传递参数:

–stringparam ulink.show 0

这样,最终生成的pdf中,就不显示带链接的文字的后面的那个url地址了。

转载请注明:在路上 » 【已解决】去掉docbook中输出的pdf中,除了带链接的文字之外的那个链接地址

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.167 seconds, using 22.02MB memory