0

次のケースについて、私が何をすべきかを理解し、アドバイスするのを手伝ってください。Excel 2007/2010 マクロを使用して 1 つの XML を別の XML に変換する必要があり、約 6 年前に Java の XSLT に問題なく使用した Altove MapForce ツールを使用しようとしました。マッピング XML (スタイルシートと想定) を以下にコピーします。ただし、Excel VB を実行すると、xmlns:fn="http://www.w3.org/2005/xpath-functions" に関数が含まれていないというエラー メッセージが表示されます。

MapfForce のライブラリから「contains」や「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 に答える