1

I'm planning an XSLT transformation to some WordML documents (2003) to DITA. Fairly straight forward... except, I need to save the inline binary of the png file (in the tag) as a file at a level above the XML output file. Is it possible to output to a png in XSLT, or am I going to have to process it through a Java program first?

4

1 回答 1

1

你确定 WordML 有内联二进制文件吗?我认为你的假设是不正确的。它很可能是 base64 编码的数据。我们之前已经这样做了,我挖出了她从 WordML 生成 DITA 的代码,图像使用其 base64 编码字节填充到“src”属性中:

<image>
<xsl:variable name="srcfile" select="concat('/word/',string($rels/rel:Relationships/rel:Relationship[@Id = $src]/@Target))"/>
<xsl:variable name="imagepkg" select="//pkg:part[@pkg:name=$srcfile]"/>
<xsl:variable name="attachmentContentType" select="$imagepkg/@pkg:contentType"/>
<xsl:variable name="encodedImageBytes" select="$imagepkg/pkg:binaryData/text()"/>                        
<xsl:variable name="scale">
    <xsl:choose>
        <xsl:when test="w:r/w:drawing/wp:inline/a:graphic/a:graphicData/pic:pic/pic:spPr/a:ln/@w">
            <xsl:value-of select="number(w:r/w:drawing/wp:inline/a:graphic/a:graphicData/pic:pic/pic:spPr/a:ln/@w)"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$defscale"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:variable> 
<xsl:attribute name="width">
    <xsl:value-of select="concat(string(number(w:r/w:drawing/descendant::wp:extent/@cx div ($scale * 96))),'in')"/>
</xsl:attribute>
<xsl:attribute name="height">
    <xsl:value-of select="concat(string(number(w:r/w:drawing/descendant::wp:extent/@cy div ($scale * 96))),'in')"/>
</xsl:attribute>
<xsl:attribute name="src">
    <xsl:text>data:</xsl:text>
    <xsl:value-of select="$attachmentContentType"/>                
    <xsl:text>;base64,</xsl:text>
    <xsl:value-of select="$encodedImageBytes"/>
</xsl:attribute>
</image>

如果需要,您可以将所有 base64 编码信息放入单独的文件中,但二进制数据不在 WordML 中。如果您希望它与外部文件一步到位,您可以编写一个 java 扩展函数(假设您使用像 Saxon 这样的 java XSLT)并传入 base64 编码的图像,该函数将解码并写入磁盘。

于 2013-06-18T23:16:09.743 回答