Hob*_*bes 3 xml xslt saxon xslt-2.0
我有一个 XML 文件,其中包含以文件名开头的部分:
<madcapfile filename="C:\1\Outputpath\The 7% solution.xlf">
Run Code Online (Sandbox Code Playgroud)
每个部分都必须保存到一个单独的文件中。这是我的 XSLT:
<xsl:template match="madcapfile">
<xsl:variable name="file1" select="concat('file:///',@filename)"/>
<xsl:variable name="file2" select="encode-for-uri($file1)"/>
<xsl:variable name="file3" select="concat('file:///',replace(@filename,'%','%25'))"/>
<xsl:result-document method="xml" href="{$file2}">
<xsl:apply-templates select="node()"/>
</xsl:result-document>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
变量 file1、file2、file3 是我迄今为止的尝试。变量 file1 在正确位置为所有文件创建文件,文件名中带有 % 的文件除外。
变量 file3 在所有文件的正确位置创建文件,因此这是一个有效的解决方案。
使用变量 file2 会出现错误:XSLT 处理器 (Saxon 9.7) 尝试将文件写入
C:\Path-to-XSLT\C:\1\Outputpath\The 7% solution.xlf
Run Code Online (Sandbox Code Playgroud)
即它看起来像 encode-for-uri 将其输入视为相对路径,即使它以“C:\”开头
我也尝试将“file:///”添加到路径的开头,这不会改变encode-for-uri 的行为。
有没有办法强制 encode-for-uri 将其输入视为绝对路径?
有两个问题,href属性需要一个 URI,而在 URI 中,分隔符是Windows 文件路径中使用的,/而不是\使用的。此外,使用encode-for-uri转义任何反斜杠。
所以要解决这个问题,你应该用正斜杠替换任何反斜杠,然后你可以使用encode-for-uri转义百分号:
concat('file:///', encode-for-uri(replace(@filename, '\\', '/')))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
605 次 |
| 最近记录: |