【问题标题】:How can I insert multiple files contents into xml?如何将多个文件内容插入 xml?
【发布时间】:2021-07-02 11:33:42
【问题描述】:

我有一个为 Workday 集成提供输入的 xml 文件。输入是一个 xml 文件,通常在 Excel 中打开并通过粘贴 SQL 查询的输出来填充。然而,这个特定的 xml 需要填充超过 Excel 单元格大小限制的数据。单元格数据是 base64 编码的 .pdf 文件。一列中的每个单元格将包含一个 .pdf 文件的内容。 我能够创建 xml 文件内容单元格标记有一个短文本字符串(“文件内容”),但我需要一些方法来替换这些标记编码的文件内容。 我确信必须有用于此的工具,但我对 xml 操作相对较新。我想到的可能性是 Powershell、xslt 或 Oxygen 应用程序之一,但我不知道哪个是最好的(XML 编辑器?作者?)。附件是在 Excel 和 Oxygen 中打开的 xml 图像。

【问题讨论】:

标签: xml powershell xslt oxygenxml


【解决方案1】:

带有 EXPath 文件模块和 Saxon EE 和流的 XSLT 3 将在某种程度上符合

<?xml version="1.0" encoding="UTF-8"?>
<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"
    xpath-default-namespace="put excel namespace here"
    exclude-result-prefixes="#all"
    version="3.0">

    <!-- adjust these integers to match the cell index of the real input -->
    <xsl:param name="cell-index-file-name" as="xs:integer" select="3"/>
    <xsl:param name="cell-index-file-contents" as="xs:integer" select="6"/>
    
    <xsl:mode streamable="yes" on-no-match="shallow-copy" use-accumulators="#all"/>
    
    <xsl:accumulator name="pos" as="xs:integer?" initial-value="()" streamable="yes">
        <xsl:accumulator-rule match="Table" select="()"/>
        <xsl:accumulator-rule match="Table/Row" select="0"/>
        <xsl:accumulator-rule match="Table/Row/Cell" select="$value + 1"/>
    </xsl:accumulator>
    
    <xsl:accumulator name="file-name" as="xs:string?" initial-value="()" streamable="yes">
        <xsl:accumulator-rule match="Row/Cell[accumulator-before('pos') eq $cell-index-file-name]/text()" select="data()"/>
    </xsl:accumulator>
    
    <xsl:template match="Row/Cell[accumulator-before('pos') eq $cell-index-file-contents]">
        <xsl:copy>
            <xsl:value-of select="file:read-binary(resolve-uri(accumulator-before('file-name')))"/>
        </xsl:copy>
    </xsl:template>
    
</xsl:stylesheet>

【讨论】:

  • 感谢马丁的推荐。我确实安装了 Java 并下载了 Saxon Enterprise Edition 并进行了一些实验。这对我来说很有教育意义,但出于各种原因,包括我本来应该拥有的学习曲线,我使用了更熟悉的工具来克服这个问题。我在 App.Engine 中使用 PeopleCode 来生成 xml 的 Excel“行”块。我使用 PeopleSoft 提供的函数 GetBase64StringFromBinary() 对文件内容进行编码。
猜你喜欢
  • 2022-01-09
  • 1970-01-01
  • 2013-05-05
  • 2017-08-04
  • 2020-06-30
  • 1970-01-01
  • 2022-11-14
  • 2011-10-09
  • 1970-01-01
相关资源
最近更新 更多