eXist-db 中 XSL-FO 中的图像 [英] Images in XSL-FO in eXist-db

查看:19
本文介绍了eXist-db 中 XSL-FO 中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我之前的问题中,我触及了更广泛的路径问题及其在 eXist-db 应用程序中的识别.

In my former question I have touched a broader problem of paths and their recognizing inside an eXist-db app.

目前,我无法将图像转换为 PDF 文件.我已经尝试了 2 次安装 eXist(2.2 和 3RC)和许多可能的场景.当然,我已经测试过这些图片可以通过浏览器访问.

At the moment, I am not able to get images in to PDF files. I have tried 2 installations of eXist (2.2 and 3RC) and many possible scenarios. Of course, I have tested those pictures are reachable through the browser.

在源文件中,我试过:

1. <graphic url="img/tealover.jpg"/>
2. <graphic url="/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg"/>
3. <graphic url="http://46.28.111.241:8081/exist/rest/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg"/>

4. <graphic url="url(img/tealover.jpg)"/>
5. <graphic url="url(/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg)"/>
6. <graphic url="url(http://46.28.111.241:8081/exist/rest/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg)"/>

7. <graphic url="url('img/tealover.jpg')"/>
8. <graphic url="url('/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg')"/>
9. <graphic url="url('http://46.28.111.241:8081/exist/rest/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg')"/>

正如预期的那样,示例 3、6 和 9 可以仅当我在源中以硬编码链接的形式提供它们时.如果我在 XSLT 样式表中建立链接,它们在 FO 文件中完全相同,但在生成的 PDF 中没有任何内容.

As expected, samples 3, 6 and 9 work but only if I have them in a form of hardcoded links in the source. If I build up the links in my XSLT stylesheet, they are exactly the same in the FO file but there is nothing in the produced PDF.

在 FO 文件中生成的等效项:

Equivalents produced in FO file:

1. <fo:external-graphic src="img/tealover.jpg"/>
2. <fo:external-graphic src="/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg"/>
3. <fo:external-graphic src="http://46.28.111.241:8081/exist/rest/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg"/>

4. <fo:external-graphic src="url(img/tealover.jpg)"/>
5. <fo:external-graphic src="url(/db/apps/karolinum-apps/data/2015080/img/tealover.jpg)"/>
6. <fo:external-graphic src="url(http://46.28.111.241:8081/exist/rest/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg)"/>

7. <fo:external-graphic src="url('img/tealover.jpg')"/>
8. <fo:external-graphic src="url('/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg')"/>
9. <fo:external-graphic src="url('http://46.28.111.241:8081/exist/rest/db/apps/karolinum-apps/data/mono/2015080/img/tealover.jpg')"/>

当我将这些链接硬编码到源代码中时,在样式表中src="{@url}".当我到处使用短版 url (url="img/tealover.jpg") 时,在我使用的属性样式表中

When I hard-code those links into the source, in the stylesheet works src="{@url}". When I use the short version of url everywhere (url="img/tealover.jpg"), in the attribute stylesheet I use

<xsl:value-of select="concat('http://46.28.111.241:8081/exist/rest', $imgPath, @url)"/>

或直接在模板中

src="concat('http://46.28.111.241:8081/exist/rest', $imgPath, @url)"

$imgPath 变量作为参数从应用程序传递:

The $imgPath variable is passed as a param from the application:

let $bookUri := base-uri($resource)
let $imgPath := replace($bookUri, '[^/]*?$', '')

这样,链接 1、4 和 7 应该可以工作,其余的就一团糟.我可以在 eXide 中复制这些链接,它们仍然可以在浏览器中使用.

With this, links 1, 4 and 7 should work, the rest is a mess. I can copy these links in eXide and they still work in the browser.

当我进行测试时,一切看起来都很好.在PDF中,仍然没有图片.我想一定有一个小细节我现在遗漏了.

When I am testing, everything looks fine. In the PDF, there is still no picture. I guess there has to be a tiny detail I am missing now.

推荐答案

得到了解决方案.出乎意料的是,最好的办法是让 url 保持原样并专注于解析根路径.有了这个,FOP 处理器就能够解析相对路径,一切都按预期工作.就我而言,我将动态配置文件提供给 xslfo:render() 函数.最重要的部分是:

Got the solution. Unexpectedly, the best thing is to let urls as they are and focus on resolving of the root paths. With this the FOP processor is able to resolve relative paths and everything works as expected. In my case, I serve dynamic config file to the xslfo:render() function. The most important part is:

<hyphenation-base>{replace(request:get-url(), '/apps(.*?)$', '/rest')}/db/apps/karolinum-apps/modules/resources/hyph/</hyphenation-base>
<hyphenation-pattern lang="cs" country="CZ">cs</hyphenation-pattern>
<base>{replace(request:get-url(), '/apps(.*?)$', '/rest') || replace(base-uri($doc), '[^/]*?$', '')}</base>
<font-base>{replace(request:get-url(), '/apps(.*?)$', '/rest')}/db/apps/karolinum-apps/modules/resources/fonts/</font-base>

现在我可以将所有内容存储在项目中并在我的源文件中使用相对路径.希望这个解决方案能在下一次测试中幸存下来!如果您知道如何执行此操作的更优雅的方法,请告诉我(好吧,首先我可以将那些笨拙的路径操作放入变量中).

Now I am able to store everything inside the project and use relative paths in my source files. Hope this solution will survive next testing! If you knew more elegant way how to do this, please, let me know (ok, first of all I could put those clumsy path operations into variables).

这篇关于eXist-db 中 XSL-FO 中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆