【问题】
docbook中,对于这样的xml源码:
1 | < para >本文章遵从:< ulink url = "http://creativecommons.org/licenses/by-nc/2.5/cn/" >署名-非商业性使用 2.5 中国大陆(CC BY-NC 2.5)</ ulink ></ para > |
生成的html是这样的:
这样的是我所要的效果,即带链接的文字,即可。
而生成的pdf中,却显示是这样的:
即,除了带链接的文字之外,还多余的显示出对应的链接地址,这个不是我所想要的,所以希望把pdf中多余显示出来的链接地址去掉。
【解决过程】
1.推断到,这些输入方面的内容控制,应该是对应的xls中控制的,所以就去到xsl中找对应的xlink方面的配置。
最后终于在xref中找到了:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | < 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,然后找到了这里:
参考其内容,本来以为是要把其中的:
1 | < xsl:param name = "ulink.show" select = "1" ></ xsl:param > |
写如到对应的xls或xml中,不过后来看到了xsl:param这个字眼,突然想到,估计也是类似之前使用xsltproc时候所用到的,通过stringparam传入进去的参数:
1 | 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 |
所以,就用下面的代码,去试试:
1 | 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,结果就实现了所需要的效果了:
【总结】
想要输入的pdf中的带链接的文字后面的那个url地址不显示,可以通过给xsltproc传递参数:
–stringparam ulink.show 0 |
这样,最终生成的pdf中,就不显示带链接的文字的后面的那个url地址了。