0

请帮助我了解并建议我应该为以下情况做些什么。我必须使用 Excel 2007/2010 宏将一个 XML 转换为另一个 XML,并且我尝试使用 Altove MapForce 工具,大约 6 年前我在 Java 中使用 XSLT 没有问题。映射 XML(应该是样式表)复制如下。但是,Excel VB 执行会引发有关 xmlns:fn="http://www.w3.org/2005/xpath-functions" 不包含任何函数的错误消息。

我确实使用了 MapfForce 库中的“包含”和“if-else”等转换函数。

怎么了?

我将非常感谢这方面的任何帮助(特别是,我需要及时)。

问候, - 迈克

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:core="http://www.altova.com/MapForce/UDF/core" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="core xs fn">
<xsl:template name="core:convert-uri-to-windows-file-path">
    <xsl:param name="uri" select="()"/>
    <xsl:choose>
        <xsl:when test="fn:starts-with($uri, 'file://')">
            <xsl:choose>
                <xsl:when test="(fn:substring($uri, xs:double('6'), xs:double('3')) = '///')">
                    <xsl:variable name="var1_resultof_url_decode" as="xs:string">
                        <xsl:call-template name="core:url-decode">
                            <xsl:with-param name="uri" select="fn:substring($uri, xs:double('9'), xs:double(fn:string-length($uri)))" as="xs:string"/>
                        </xsl:call-template>
                    </xsl:variable>
                    <xsl:sequence select="fn:translate($var1_resultof_url_decode, '/|', '\:')"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:sequence select="$uri"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:when>
        <xsl:otherwise>
            <xsl:sequence select="$uri"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
<xsl:template name="core:url-decode">
    <xsl:param name="uri" select="()"/>
    <xsl:choose>
        <xsl:when test="fn:contains($uri, '%')">
            <xsl:variable name="var1_resultof_url_decode_part" as="xs:string">
                <xsl:call-template name="core:url-decode-part">
                    <xsl:with-param name="uripart" select="fn:substring-after($uri, '%')" as="xs:string"/>
                </xsl:call-template>
            </xsl:variable>
            <xsl:sequence select="fn:concat(fn:substring-before($uri, '%'), $var1_resultof_url_decode_part)"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:sequence select="$uri"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
<xsl:template name="core:url-decode-part">
4

1 回答 1

0

Excel VBA 使用的 XSL 处理器仅接受 XSLT 版本 1,而您的 XSLT 是版本 2。不过,将其转换为版本 1 看起来并不难 - 它似乎没有使用任何版本 2 的特定功能。

这是您发布的部分的版本 1 的转换:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template name="convert-uri-to-windows-file-path">
    <xsl:param name="uri"/>
    <xsl:choose>
      <xsl:when test="starts-with($uri, 'file://')">
        <xsl:choose>
          <xsl:when test="substring($uri, 6, 3) = '///'">
            <xsl:variable name="var1_resultof_url_decode">
              <xsl:call-template name="url-decode">
                <xsl:with-param name="uri" select="substring($uri, 9, string-length($uri))"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:value-of select="translate($var1_resultof_url_decode, '/|', '\:')"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$uri"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$uri"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="url-decode">
    <xsl:param name="uri"/>
    <xsl:choose>
      <xsl:when test="contains($uri, '%')">
        <xsl:variable name="var1_resultof_url_decode_part">
          <xsl:call-template name="url-decode-part">
            <xsl:with-param name="uripart" select="substring-after($uri, '%')"/>
          </xsl:call-template>
        </xsl:variable>
        <xsl:value-of select="concat(substring-before($uri, '%'), $var1_resultof_url_decode_part)"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$uri"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
于 2013-10-06T22:08:55.880 回答