使用 XSLT 2.0 显示目录中的图像

Use XSLT 2.0 to display an image from a directory

团队,

我正在使用 XLST 2.0 从 XML 数据创建 MS Word 文档。我正在创建一个 header 并希望从本地目录调用图像文件以显示我们公司的徽标。使用我正在使用的软件,我无法使用 MS Word 模板来调用。这是计费软件,每次收到账单(使用 XML 数据)时都需要即时创建每个 MS word 文档。

我广泛搜索了该站点并尝试了大部分给出的示例,但均无济于事。任何帮助或指导将不胜感激。

这是我要创建的 MS Word 文档中 header 的结果...

这是我的 header...

的 XSL
<xsl:stylesheet xmlns:aml="http://schemas.microsoft.com/aml/2001/core" 
    xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" 
    xmlns:fo="http://www.w3.org/1999/XSL/Format" 
    xmlns:kmf="http://www.kleinmundo.com/functions" 
    xmlns:o="urn:schemas-microsoft-com:office:office" 
    xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core" 
    xmlns:tlr="http://www.elite.com/functions" 
    xmlns:st1="urn:schemas-microsoft-com:office:smarttags" 
    xmlns:v="urn:schemas-microsoft-com:vml" 
    xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" 
    xmlns:w10="urn:schemas-microsoft-com:office:word" 
    xmlns:wsp="http://schemas.microsoft.com/office/word/2003/wordml/sp2" 
    xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

    <xsl:template name="XS_Header" xml:space="default">
        <xsl:variable name="TW" select="1440" />
        <xsl:variable name="image-dir" select="'/Images'" />
        <w:sectPr>
            <w:hdr w:type="first">
                <w:tbl>
                    <xsl:variable name="Col1" select="2 * $TW" />
                    <xsl:variable name="Col2" select="5.5 * $TW" />
                    <w:tblPr>
                        <w:tblW w:w="0" w:type="dxa"/>
                        <w:tblCellMar>
                            <w:left w:w="0" w:type="dxa"/>
                            <w:right w:w="0" w:type="dxa"/>
                        </w:tblCellMar>
                    </w:tblPr>
                    <w:tblGrid>
                        <w:gridCol w:w="{$Col1}"/>
                        <w:gridCol w:w="{$Col2}"/>
                    </w:tblGrid>
                    <w:tr>
                        <w:trPr>
                            <w:cantSplit/>
                            <w:tblHeader/>
                        </w:trPr>
                        <!--LOGO COLUMN -->
                        <w:tc>
                            <w:tcPr>
                                <w:tcW w:w="{$Col1}" w:type="dxa"/>
                                <w:vAlign w:val="bottom"/>
                            </w:tcPr>
                            <w:p>
                                <w:pPr>
                                    <w:keepNext/>
                                    <w:keepLines/>
                                </w:pPr>
                                <w:r>
                                    <w:t>LOGO HERE</w:t>
                                </w:r>
                            </w:p>
                        </w:tc>
                        <!-- ADDRESS INFO COLUMN -->
                        <w:tc>
                            <w:tcPr>
                                <w:tcW w:w="{$Col2}" w:type="dxa"/>
                                <w:vAlign w:val="bottom"/>
                            </w:tcPr>
                            <w:p>
                                <w:pPr>
                                    <w:keepNext/>
                                    <w:keepLines/>
                                    <w:jc w:val="right" />
                                </w:pPr>
                                <w:r>
                                    <w:rPr>
                                        <w:sz w:val="16" />
                                    </w:rPr>
                                    <w:t>Company Address  |  City, State  ZIP  |  TEL 555.555.1234  |  FAX 555.555.4321</w:t>
                                </w:r>
                            </w:p>
                        </w:tc>
                    </w:tr>
                </w:tbl>
                <w:sectPr>
                    <w:pgSz w:w="12240" w:h="15840" w:orient="portrait" w:code="1" />
                    <w:pgMar w:top="720" w:right="720" w:bottom="720" w:left="720" w:header="720" w:footer="720" w:gutter="0" />
                    <w:cols w:space="720" />
                    <w:titlePg />
                    <w:docGrid w:line-pitch="272" />
                </w:sectPr>
            </w:hdr>
            <w:titlePg />
            <w:hdr w:type="odd">
            </w:hdr>
            <w:ftr w:type="first">
                <w:p>
                    <w:r>
                        <w:t />
                    </w:r>
                </w:p>
            </w:ftr>
            <w:titlePg />
            <w:ftr w:type="odd">
                <w:p>
                    <w:r>
                        <w:t />
                    </w:r>
                </w:p>
            </w:ftr>
            <w:pgNumType w:start="1" />
            <w:cols w:space="720" />
        </w:sectPr>
    </xsl:template>
</xsl:stylesheet>

-尼克

这是我自己想出来的。这就是我所做的。

我创建了一个 DOCX 文件,其中只有文档正文中的图像。然后我创建了一个书签,突出显示了图像并将书签命名为“logo”。我将 DOCX 文件保存到 C:\images\logo_template.docx

然后我进入我的 XSLT 文件并调用指向书签的 DOCX 文件,如下所示:

<w:p>
  <w:r>
    <w:t>
      ~INS~<xsl:value-of select"'C:\images\logo_template.docx|logo'" />~/INS~
    </w:t>
  </w:r>
</w:t>

这将图像文件扔进了我正在从我的账单生成软件中编译的生成的 MS Word 文件中。

此致,

-尼克