SSIS XSLT转换

时间:2009-12-23 16:52:28

标签: xslt ssis

我在SQL Server 2005,VS 2005 SP2上使用SSIS。

我创建了一个XSLT来将XML转换为CSV格式。当我通过XML Spy运行它时它工作正常。我在内部配置了XML Task和SSIS包来转换XML文件。不幸的是,当SSIS执行转换时,它不包括每条记录末尾的CR / LF - 我留下了一条单线。

我在下面提到了XSLT。任何人都可以让我知道为什么SSIS忽略了 ?

我还粘贴了一个示例XML文档。

非常感谢,

罗布。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="utf-8"/>
<xsl:strip-space elements="*"/>
    <xsl:template match="/pptxn">
        <xsl:variable name="fileName" select="/pptxn/file_name"/>
        <xsl:variable name="sendingOrg" select="/pptxn/sending_org"/>
        <xsl:variable name="dateCreated" select="/pptxn/date_created"/>
        <xsl:variable name="timeCreated" select="/pptxn/time_created"/>
        <xsl:variable name="sequenceNumber" select="/pptxn/sequence_number"/>
        <xsl:text>FileName,SendingOrg,DateCreated,TimeCreated,SequenceNumber,PartnerNumber,PartnerOutletRef,CardAccountNumber,TransactionDate,TransactionTime,Spend,PartnerPoints,PartnerReference,PartnerPosId</xsl:text>
    <xsl:text>&#xD;</xsl:text>
        <xsl:for-each select="transaction">
            <xsl:value-of select="$fileName"/>,<xsl:value-of select="$sendingOrg"/>,<xsl:value-of select="$dateCreated"/>,<xsl:value-of select="$timeCreated"/>,<xsl:value-of select="$sequenceNumber"/>,<xsl:value-of select="partner_number"/>,<xsl:value-of select="partner_outlet_ref"/>,<xsl:value-of select="card_account_number"/>,<xsl:value-of select="transaction_date"/>,<xsl:value-of select="transaction_time"/>,<xsl:value-of select="spend"/>,<xsl:value-of select="partner_points"/>,<xsl:value-of select="partner_reference"/>,<xsl:value-of select="partner_pos_id"/>
            <xsl:text>&#xD;</xsl:text>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

现在是XML - &gt;

<?xml version="1.0" encoding="UTF-8"?>
<pptxn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Y:\PartnerPoints\XML\PointsPartnerRequest.xsd">
    <file_name>PPRequest.xml</file_name>
    <sending_org>1</sending_org>
    <date_created>20091121</date_created>
    <time_created>153421</time_created>
    <sequence_number>2</sequence_number>
    <transaction_count>3</transaction_count>
    <transaction>
        <partner_number>1</partner_number>
        <partner_outlet_ref>outlet ref 1</partner_outlet_ref>
        <card_account_number>1</card_account_number>
        <transaction_date>20091221</transaction_date>
        <transaction_time>091256</transaction_time>
        <spend>21.34</spend>
        <partner_points>40</partner_points>
        <partner_reference>shop x1</partner_reference>
        <partner_pos_id>pos id 1</partner_pos_id>
    </transaction>
    <transaction>
        <partner_number>2</partner_number>
        <partner_outlet_ref>outlet ref 2</partner_outlet_ref>
        <card_account_number>2</card_account_number>
        <transaction_date>20091222</transaction_date>
        <transaction_time>091257</transaction_time>
        <spend>21.35</spend>
        <partner_points>41</partner_points>
        <partner_reference>shop x2</partner_reference>
        <partner_pos_id>pos id 2</partner_pos_id>
    </transaction>
        <transaction>
        <partner_number>3</partner_number>
        <partner_outlet_ref>outlet ref 3</partner_outlet_ref>
        <card_account_number>3</card_account_number>
        <transaction_date>20091223</transaction_date>
        <transaction_time>091258</transaction_time>
        <spend>21.36</spend>
        <partner_points>42</partner_points>
        <partner_reference>shop x3</partner_reference>
        <partner_pos_id>pos id 3</partner_pos_id>
    </transaction>
</pptxn>

2 个答案:

答案 0 :(得分:2)

您可能需要更改

<xsl:text>&#xD;</xsl:text>

<xsl:text>&#xD;&#xA;</xsl:text>

答案 1 :(得分:2)

我将char代码从十六进制更改为十进制,现在它适用于SSIS 2005:)

<xsl:text>&#13;&#10;</xsl:text>
很奇怪......