我有base64编码内容(图像文件),我想使用XSLT / XPath 2.0将其写入外部文件。
这是我的输入文件
<root>
<img>iVBORw0KGgoAAAANSUhEUgAABAAAAAMAAQMAAACAdIdOAAAABlBMVEUAAAD///
+l2Z/dAAABpElEQVR42u3OQQ0AMAgEsHOAf7Wbhn0GIa2C5jSLgICAgICAgICAgI
CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgMDgQB6UgICAgICAgICAgICAgI
CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
CAgICAgICAgICAgICAgICAgICAgICAgMDKwB8CAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAu2BC6XQXOr9fnZDAAAAAElFTkSuQmCC</img>
</root>
这是我尝试编写文件:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:file="http://expath.org/ns/file">
<xsl:template match="img">
<myimg>
<xsl:variable name="filename" select="'hello.png'"/>
<xsl:attribute name="filename" select="$filename"/>
<xsl:value-of select="file:write-binary($filename,xs:base64Binary(.))" />
</myimg>
</xsl:template>
</xsl:stylesheet>
但&#34;没有任何反应&#34;,这意味着我得到一个带有myimg作为根标签(预期)的XML文件,但没有文件写入当前目录。我该怎么办?
我使用Saxon-PE-9.7.0.15和oXygen XML
编辑:使用hello.png
作为文件名(以减少混淆)
答案 0 :(得分:2)
这似乎与在oXygen中使用Saxon和EXPath文件模块有关,因为当我在Saxon外面运行XSLT时,文件是在与XML输入和样式表代码相同的目录中创建的,但是在oXygen里面使用<xsl:message select="'current-dir() ', file:current-dir()"/>
表示文件模块使用不同的目录来读取和写入。