2016-01-22 25 views
0

我需要抓取几张图片,并将它们放到通过Apache FOP生成的pdf中。在eXist之外,我没有问题。使用eXist,模板无法正常工作,输出中没有图像 - 可能是路径存在问题。eXist-db - XSLT中的路径

的“文件”的结构是:

project/data/file.xml 
project/data/img/*pictures.jpg 

测试来源:

<figure> 
    <graphic url="img/tealover.jpg"/> 
</figure> 

<figure> 
    <graphic url="./img/tealover.jpg"/> 
</figure> 

<figure> 
    <graphic url="/db/apps/karolinum-apps/data/img/tealover.jpg"/> 
</figure> 

模板:

<xsl:template match="tei:figure/tei:graphic"> 
    <fo:block> 
     <fo:external-graphic src="{@url}" xsl:use-attribute-sets="images"/> 
    </fo:block> 
    <xsl:apply-templates/> 
</xsl:template> 

哪里可能是问题?我是否错过了eXist的一些设置?在ePub制作期间收集图像时,这没有问题。

UPDATE

XSL-FO输出:

<fo:block> 
    <fo:external-graphic width="50%" content-height="100%" content-width="scale-to-fit" scaling="uniform" src="img/tealover.jpg"/> 
</fo:block> 
<fo:block> 
    <fo:external-graphic width="50%" content-height="100%" content-width="scale-to-fit" scaling="uniform" src="./img/tealover.jpg"/> 
</fo:block> 
<fo:block> 
    <fo:external-graphic width="50%" content-height="100%" content-width="scale-to-fit" scaling="uniform" src="/db/apps/karolinum-apps/data/img/tealover.jpg"/> 
</fo:block> 
+0

你有办法检查创建的FO吗? src'属性是否为空? –

+0

对于我来说,我试图弄清楚发生了什么,但它与源代码中的相同。我会再次确保。但我想这个问题可能在别的地方。 –

回答

1

的XSL-FO处理器有不知道如何从这些URL的图像,因为它并不知道在哪里解决对这些路径。

您应该改用了XSL-FO处理器可以取消引用,因此,例如,如果你的形象在这个路径存储中不存在绝对网址:

/db/apps/karolinum-apps/data/img/tealover.jpg

你应该使用的网址:

http://localhost:8080/exist/rest/db/apps/karolinum-apps/data/img/tealover.jpg

我假设eXist正在localhost端口8080上运行,如果没有,那么只需调整上面的URL以反映您的设置。

+0

谢谢!它的工作原理非常合理!但是,在我将问题标记为已回答之前,如果我完全禁用了eXist的REST功能(在O'Reilly的新书中推荐),该怎么办?有没有解决方法? –

+0

基本上你的XSL-FO处理器知道如何访问绝对URI。如果你想禁用REST API,你可以考虑在WebDAV或RESTXQ API中使用URI。如果你想禁用这些文件,你可以用'$ EXIST_HOME/webapp/WEB-INF/data/fs'解决你的二进制文件路径,这是eXist实际放置你的二进制文件的地方。所以,如果你的$ EXIST_HOME是'/ usr/local/eXist',你可以传递如下的URL:'files:/// usr/local/eXist/webapp/WEB-INF/data/fs/db/apps /卡罗莱姆-应用/数据/ IMG/tealover.jpg'。但是这种方法没有证件/脆弱性。 – adamretter

+0

另外,eXist O'Reilly的书只建议禁用你不需要的东西。你仍然可以使用REST API,但是如果你愿意的话,不能让任何人访问它。 – adamretter

0

看来这做的伎俩:

<xsl:template match="tei:figure/tei:graphic"> 
    <fo:block> 
     <fo:external-graphic src="url('{resolve-uri(@url, base-uri(.))}')" xsl:use-attribute-sets="images"/> 
    </fo:block> 
    <xsl:apply-templates/> 
</xsl:template> 

UPDATE

有趣!起初它像一个魅力。后来,我稍微重新安排了项目的结构(但文档附近的环境几乎相同),现在它不起作用。它的日志:

exerr:ERROR Exception while transforming node: Base URI {} is not an absolute URI [at line 11, column 19] In function: 
fop:render-pdf(node()*) [12:5:/db/apps/karolinum-apps/modules/create-pdf.xqm] 

但显然问题在于这行代码。

即使我尝试<xsl:value-of select="resolve-uri(@url, base-uri(.))"/>,它抱怨

exerr:ERROR Exception while transforming node: Base URI {} is not an absolute URI [at line 16, column 9] 

无法理解此刻这样微小的细节。

+0

如果您执行'base-uri(root (。))?? – adamretter

+0

同样的错误,我正在密集测试,看起来XSLT方法似乎是专注于调整FO处理器,现在它可以在'fop中提供''。 conf'通过'rest'动态地提供给'render-fop()'函数和图像的绝对路径。然而,与字体和''不一样,即使它们真的可以通过'rest'真的不满意这个东西 –

+0

在这里回答: http://stackoverflow.com/questions/35038690/images-in-xsl-fo-in-exist-db/35083165#35083165 –