获取有关要在输出中使用的附件的信息,例如文件大小
get information on attachments to use in the output like file size
我需要将像 这样的 link 翻译成存在文件大小的 link,像 。
pdf 存在于包含输入文件的文件夹中。
有没有办法用 xslt 2.0 做到这一点?
有人可以指出我正确的方向吗?
谢谢!
假设您可以使用 Saxon 9 的商业版本(即 PE 或 EE)或任何其他支持 EXPath file module 的 XSLT 2.0 处理器,您可以按如下方式使用它:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:file="http://expath.org/ns/file"
exclude-result-prefixes="xs file"
version="2.0">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="a/@href[file:exists(resolve-uri(., base-uri()))]">
<xsl:copy/>
<xsl:attribute name="size" select="concat(file:size(resolve-uri(., base-uri())) idiv 1024, 'KB')"/>
</xsl:template>
</xsl:stylesheet>
使用 Saxon 进行转换
<root>
<a href="test2016082601.pdf">doc</a>
</root>
进入
<root>
<a href="test2016082601.pdf" size="141KB">doc</a>
</root>
我需要将像 这样的 link 翻译成存在文件大小的 link,像 。 pdf 存在于包含输入文件的文件夹中。 有没有办法用 xslt 2.0 做到这一点? 有人可以指出我正确的方向吗?
谢谢!
假设您可以使用 Saxon 9 的商业版本(即 PE 或 EE)或任何其他支持 EXPath file module 的 XSLT 2.0 处理器,您可以按如下方式使用它:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:file="http://expath.org/ns/file"
exclude-result-prefixes="xs file"
version="2.0">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="a/@href[file:exists(resolve-uri(., base-uri()))]">
<xsl:copy/>
<xsl:attribute name="size" select="concat(file:size(resolve-uri(., base-uri())) idiv 1024, 'KB')"/>
</xsl:template>
</xsl:stylesheet>
使用 Saxon 进行转换
<root>
<a href="test2016082601.pdf">doc</a>
</root>
进入
<root>
<a href="test2016082601.pdf" size="141KB">doc</a>
</root>