我試圖將XSL轉換應用於SSIS包XML任務內的XML文件。在SSIS的XML任務中使用/實現exsl函數node-set()
一切都很好,但不幸的是,由於我需要使用函數node-set()
,所以我的XSL比正常略微「便攜」。我的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任務:
Error: 0xC002F304 at XML Task, XML Task: An error occurred with the following error message: "Function 'msxsl:node-set()' has failed.".
我使用VS2005來設計包裝,因爲它是2005年版的SSIS的。
關於我如何進行的任何想法,非常感謝。
我在調用一個實現EXSLT str的模板:split函數將一個字符串「tokenise」到它的組成元素中,例如,
<token>Kermit</token>
<token>T</token>
<token>Frog</token>
這被存儲在變量$ familyNames,我然後遍歷:「柯密Ť蛙」將如下被返回。但是,由於這是作爲結果返回的樹片段,我需要用函數msxsl:node-set()來包裝它,以便將結果視爲節點集。不知道我還能如何實現上述目標。
這裏的STR的實現:分裂,我從http://www.exslt.org/獲得:
<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>
$ familyNames從何而來?你可以發佈你創建它的XSLT的一部分嗎?也許有一種方法可以完全避免node-set()。 – Tomalak 2009-06-10 08:24:20