我正在尝试将 XSL 转换应用于 SSIS 包 XML 任务中的 XML 文件。
一切都很好,但不幸的是,我的 XSL 的“便携性”比普通的稍差,因为我需要使用该功能node-set()
。我的 XSL 的一个简化示例是:
<xsl:for-each select="msxsl:node-set($familyNames)/token">
<xsl:call-template name="PersonNameComponent">
<xsl:with-param name="nameComponentType" select="'S'" />
<xsl:with-param name="nameComponentSeqNo" select="number($noOfGivenNames) + position()" />
<xsl:with-param name="nameComponent" select="." />
<xsl:with-param name="nameTypeName" select="$familyName" />
<xsl:with-param name="roleCode" select="$roleCode" />
</xsl:call-template>
</xsl:for-each>
我在样式表声明中使用了以下命名空间:
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
这适用于 VS IDE、XMLSpy(只要我将 XSLT 引擎设置为 MSXML)等。但是,当我尝试在包中执行 XML 任务时,出现以下异常:
错误:XML 任务中的 0xC002F304,XML 任务:发生错误并显示以下错误消息:“函数 'msxsl:node-set()' has failed.”。
我正在使用 VS2005 来设计包,因为它是 SSIS 的 2005 版本。
非常感谢任何关于我如何进行的想法。
我正在调用一个实现 EXSLT str:split 函数的模板,以将字符串“标记化”为它的组成元素,例如“Kermit T Frog”将返回如下:
<token>Kermit</token>
<token>T</token>
<token>Frog</token>
这存储在变量 $familyNames 中,然后我会对其进行迭代。但是,由于这是作为结果树片段返回的,因此我需要使用函数 msxsl:node-set() 将其包装起来,以便将结果视为节点集。不知道我还能如何实现上述目标。
这是我从http://www.exslt.org/获得的 str:split 的实现:
<xsl:template name="str:split">
<xsl:param name="string" select="''" />
<xsl:param name="pattern" select="' '" />
<xsl:choose>
<xsl:when test="not($string)" />
<xsl:when test="not($pattern)">
<xsl:call-template name="str:_split-characters">
<xsl:with-param name="string" select="$string" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="str:_split-pattern">
<xsl:with-param name="string" select="$string" />
<xsl:with-param name="pattern" select="$pattern" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="str:_split-characters">
<xsl:param name="string" />
<xsl:if test="$string">
<token><xsl:value-of select="substring($string, 1, 1)" /></token>
<xsl:call-template name="str:_split-characters">
<xsl:with-param name="string" select="substring($string, 2)" />
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="str:_split-pattern">
<xsl:param name="string" />
<xsl:param name="pattern" />
<xsl:choose>
<xsl:when test="contains($string, $pattern)">
<xsl:if test="not(starts-with($string, $pattern))">
<token><xsl:value-of select="substring-before($string, $pattern)" /></token>
</xsl:if>
<xsl:call-template name="str:_split-pattern">
<xsl:with-param name="string" select="substring-after($string, $pattern)" />
<xsl:with-param name="pattern" select="$pattern" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<token><xsl:value-of select="$string" /></token>
</xsl:otherwise>
</xsl:choose>
</xsl:template>