SSIS - XML 任务未使用我创建的 XSLT-2.0 转换我的 XML 文件

Posted

技术标签:

【中文标题】SSIS - XML 任务未使用我创建的 XSLT-2.0 转换我的 XML 文件【英文标题】:SSIS - XML Task not converting my XML File using my created XSLT-2.0 【发布时间】:2019-10-23 07:40:43 【问题描述】:

我正在尝试在 SSIS 中创建一个 XML 任务,它将使用 XSLT 将 XML 文件转换为 CSV 文件。我已经根据在线示例创建了 XSLT,例如:

http://blog.hoegaerden.be/2011/04/20/loading-complex-xml-using-ssis/

Make XSLT and XML Output to a XML File

但是,我尝试在 SSIS 中运行它,但没有成功。任何人都可以检查我做了什么并指出我哪里出错了。

所以,我在准备 SSIS 时点击了这个链接:http://blog.hoegaerden.be/2011/04/20/loading-complex-xml-using-ssis/

XML 示例数据: https://pastebin.com/0hMzJy7s

<?xml version="1.0" encoding="utf-8"?><RETS ReplyCode="0" ReplyText="Operation successful"><RETS-RESPONSE xmlns="urn:CREA.Search.Property"><PropertyDetails ID="15683829" LastUpdated="Thu, 10 Aug 2017 19:35:05 GMT"><ListingID>DEMO15683829</ListingID><AgentDetails ID="1962046"><Name>DEMO Agent 1962046</Name><Phones><Phone ContactType="Business" PhoneType="Telephone">(800) 123-4455</Phone><Phone ContactType="Business" PhoneType="Fax">(800) 123-4455</Phone></Phones><Office ID="94560" LastUpdated="Thu, 10 Aug 2017 19:35:05 GMT"><Name>DEMO Office 94560</Name><LogoLastUpdated>2017-08-10 2:35:05 PM</LogoLastUpdated><Address><StreetAddress>Lorem ip</StreetAddress><AddressLine1>Lorem ip</AddressLine1><City>Grand Forks</City><Province>British Columbia</Province><PostalCode>V0H</PostalCode></Address><Phones><Phone ContactType="Business" PhoneType="Telephone">(800) 123-4455</Phone><Phone ContactType="Business" PhoneType="Fax">(800) 123-4455</Phone></Phones><Websites><Website ContactType="Business" WebsiteType="Website">http://www.demo.ca</Website></Websites><OrganizationType>Firm</OrganizationType></Office></AgentDetails><AgentDetails ID="1957061"><Name>DEMO Agent 1957061</Name><Phones><Phone ContactType="Business" PhoneType="Telephone">(800) 123-4455</Phone><Phone ContactType="Business" PhoneType="Fax">(800) 123-4455</Phone></Phones><Office ID="94560" LastUpdated="Thu, 10 Aug 2017 19:35:05 GMT"><Name>DEMO Office 94560</Name><LogoLastUpdated>2017-08-10 2:35:05 PM</LogoLastUpdated><Address><StreetAddress>Lorem ip</StreetAddress><AddressLine1>Lorem ip</AddressLine1><City>Grand Forks</City><Province>British Columbia</Province><PostalCode>V0H</PostalCode></Address><Phones><Phone ContactType="Business" PhoneType="Telephone">(800) 123-4455</Phone><Phone ContactType="Business" PhoneType="Fax">(800) 123-4455</Phone></Phones><Websites><Website ContactType="Business" WebsiteType="Website">http://www.demo.ca</Website></Websites><OrganizationType>Firm</OrganizationType></Office></AgentDetails><Board>12</Board><Business><Franchise /><Name>DEMO BUSINESS</Name></Business><Building><BathroomTotal>0</BathroomTotal><FireplacePresent>False</FireplacePresent><SizeInterior /><Type>No Building</Type><UtilityWater>Municipal water</UtilityWater></Building><Land><SizeTotal>0.23 ac|under 1 acre</SizeTotal><SizeTotalText>0.23 ac|under 1 acre</SizeTotalText><AccessType>Easy access</AccessType><Acreage>false</Acreage><Amenities>Ski hill</Amenities><Sewer>No sewage system</Sewer><SizeIrregular>0.23</SizeIrregular></Land><Address><StreetAddress>Lorem ipsum dolor sit amet</StreetAddress><AddressLine1>Lorem ipsum dolor sit amet</AddressLine1><StreetNumber>Lot 9 &amp; 17</StreetNumber><StreetName>Lorem </StreetName><StreetSuffix>Avenue</StreetSuffix><StreetDirectionSuffix>South</StreetDirectionSuffix><City>Greenwood</City><Province>British Columbia</Province><PostalCode>V0H</PostalCode><Country>Canada</Country></Address><AmmenitiesNearBy>Ski hill</AmmenitiesNearBy><CommunityFeatures>Quiet Area</CommunityFeatures><Features>Central location, Hillside, Park setting, Private setting, Treed, Wooded area, Sloping, Visual exposure, Flat site</Features><ManagementCompany>DEMO Company</ManagementCompany><MunicipalId>DEMO Municipality</MunicipalId><OwnershipType>Freehold</OwnershipType><ParkingSpaceTotal>3</ParkingSpaceTotal><Photo><PropertyPhoto><SequenceId>1</SequenceId><LastUpdated>02/02/2016 06:39:35 PM</LastUpdated><PhotoLastUpdated>Tue, 02 Feb 2016 23:39:35 GMT</PhotoLastUpdated></PropertyPhoto><PropertyPhoto><SequenceId>2</SequenceId><LastUpdated>02/02/2016 06:39:35 PM</LastUpdated><PhotoLastUpdated>Tue, 02 Feb 2016 23:39:35 GMT</PhotoLastUpdated></PropertyPhoto><PropertyPhoto><SequenceId>3</SequenceId><LastUpdated>02/02/2016 06:39:35 PM</LastUpdated><PhotoLastUpdated>Tue, 02 Feb 2016 23:39:35 GMT</PhotoLastUpdated></PropertyPhoto><PropertyPhoto><SequenceId>4</SequenceId><LastUpdated>02/02/2016 06:39:35 PM</LastUpdated><PhotoLastUpdated>Tue, 02 Feb 2016 23:39:35 GMT</PhotoLastUpdated></PropertyPhoto><PropertyPhoto><SequenceId>5</SequenceId><LastUpdated>02/02/2016 06:39:35 PM</LastUpdated><PhotoLastUpdated>Tue, 02 Feb 2016 23:39:35 GMT</PhotoLastUpdated></PropertyPhoto><PropertyPhoto><SequenceId>6</SequenceId><LastUpdated>02/02/2016 06:39:35 PM</LastUpdated><PhotoLastUpdated>Tue, 02 Feb 2016 23:39:35 GMT</PhotoLastUpdated></PropertyPhoto><PropertyPhoto><SequenceId>7</SequenceId><LastUpdated>02/02/2016 06:39:36 PM</LastUpdated><PhotoLastUpdated>Tue, 02 Feb 2016 23:39:36 GMT</PhotoLastUpdated></PropertyPhoto></Photo><Price>10123.00</Price><PropertyType>Vacant Land</PropertyType><PublicRemarks>Lorem ipsum dolor sit amet, consectetur adipisci</PublicRemarks><RoadType>Paved road</RoadType><TransactionType>For sale</TransactionType><UtilitiesAvailable><Utility><Type>Cable</Type><Description>Lorem ips</Description></Utility><Utility><Type>Natural Gas</Type><Description>Lorem ips</Description></Utility><Utility><Type>Sewer</Type><Description>Lorem ips</Description></Utility><Utility><Type>Telephone</Type><Description>Lorem ips</Description></Utility><Utility><Type>Electricity</Type><Description>Lorem ips</Description></Utility><Utility><Type>Water</Type><Description>Lorem ips</Description></Utility></UtilitiesAvailable><ViewType>Mountain view, View, City view</ViewType><ZoningType>Residential</ZoningType></PropertyDetails><PropertyDetails ID="18319025" LastUpdated="Thu, 10 Aug 2017 19:39:45 GMT"><ListingID>DEMO18319025</ListingID><AgentDetails ID="1970731"><Name>DEMO Agent 1970731</Name><Phones><Phone ContactType="Business" PhoneType="Telephone">(800) 123-4455</Phone></Phones><Websites><Website ContactType="Business" WebsiteType="Website">http://www.demo.ca</Website></Websites><Office ID="77090" LastUpdated="Thu, 10 Aug 2017 19:39:45 GMT"><Name>DEMO Office 77090</Name><LogoLastUpdated>2017-08-10 2:39:45 PM</LogoLastUpdated><Address><StreetAddress>Lorem ipsum dolor</StreetAddress><AddressLine1>Lorem ipsum dolor</AddressLine1><City>Moncton</City><Province>New Brunswick</Province><PostalCode>E1C</PostalCode></Address><Phones><Phone ContactType="Business" PhoneType="Telephone">(800) 123-4455</Phone></Phones><Websites><Website ContactType="Business" WebsiteType="Website">http://www.demo.ca</Website></Websites><OrganizationType>Firm</OrganizationType></Office><Position>Salesperson</Position></AgentDetails><Board>45</Board><Business><Franchise /><Name>DEMO BUSINESS</Name></Business><Building><FireplacePresent>False</FireplacePresent></Building><Land><SizeTotalText>3694 Sq Meters|under 1/2 acre</SizeTotalText><AccessType>Year-round access</AccessType><Acreage>false</Acreage><Amenities>Church, Marina, Shopping</Amenities><Sewer>No sewage system</Sewer><SizeIrregular>3694 Sq Meters</SizeIrregular></Land><Address><StreetAddress>Lorem ipsum dolor</StreetAddress><AddressLine1>Lorem ipsum dolor</AddressLine1><StreetNumber>34-38</StreetNumber><StreetName>Lorem ipsum</StreetName><City>Bouctouche</City><Province>New Brunswick</Province><PostalCode>E4S</PostalCode><Country>Canada</Country></Address><AmmenitiesNearBy>Church, Marina, Shopping</AmmenitiesNearBy><LocationDescription>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praeteri</LocationDescription><ManagementCompany>DEMO Company</ManagementCompany><MunicipalId>DEMO Municipality</MunicipalId><OwnershipType>Freehold</OwnershipType><Photo><PropertyPhoto><SequenceId>1</SequenceId><LastUpdated>20/06/2017 02:38:43 PM</LastUpdated><PhotoLastUpdated>Tue, 20 Jun 2017 19:38:43 GMT</PhotoLastUpdated></PropertyPhoto></Photo><Price>12573.00</Price><PropertyType>Vacant Land</PropertyType><PublicRemarks>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praeteritis, inquit, gaudeo. Virtutibus igitur rectissime mihi videris et ad consuetudinem nostrae orationis vitia posuisse contraria. Non igitur de improbo, sed de callido improbo quaerimus, quali</PublicRemarks><TransactionType>For sale</TransactionType><UtilitiesAvailable><Utility><Type>Cable</Type><Description>Lorem ips</Description></Utility><Utility><Type>Telephone</Type><Description>Lorem ips</Description></Utility></UtilitiesAvailable><ViewType>View of water</ViewType><ZoningType>Residential</ZoningType></PropertyDetails><PropertyDetails ID="18319027" LastUpdated="Thu, 10 Aug 2017 19:39:46 GMT"><ListingID>DEMO18319027</ListingID><AgentDetails ID="1970731"><Name>DEMO Agent 1970731</Name><Phones><Phone ContactType="Business" PhoneType="Telephone">(800) 123-4455</Phone></Phones><Websites><Website ContactType="Business" WebsiteType="Website">http://www.demo.ca</Website></Websites><Office ID="77090" LastUpdated="Thu, 10 Aug 2017 19:39:45 GMT"><Name>DEMO Office 77090</Name><LogoLastUpdated>2017-08-10 2:39:45 PM</LogoLastUpdated><Address><StreetAddress>Lorem ipsum dolor</StreetAddress><AddressLine1>Lorem ipsum dolor</AddressLine1><City>Moncton</City><Province>New Brunswick</Province><PostalCode>E1C</PostalCode></Address><Phones><Phone ContactType="Business" PhoneType="Telephone">(800) 123-4455</Phone></Phones><Websites><Website ContactType="Business" WebsiteType="Website">http://www.demo.ca</Website></Websites><OrganizationType>Firm</OrganizationType></Office><Position>Salesperson</Position></AgentDetails><Board>45</Board><Business><Franchise /><Name>DEMO BUSINESS</Name></Business><Building><FireplacePresent>False</FireplacePresent></Building><Land><SizeTotalText>3595 Sq Meters|under 1/2 acre</SizeTotalText><AccessType>Year-round access</AccessType><Acreage>false</Acreage><Amenities>Church, Marina, Shopping</Amenities><Sewer>No sewage system</Sewer><SizeIrregular>3595 Sq Meters</SizeIrregular></Land><Address><StreetAddress>Lorem ipsum dolor</StreetAddress><AddressLine1>Lorem ipsum dolor</AddressLine1><StreetNumber>39-43</StreetNumber><StreetName>Lorem ipsum</StreetName><City>Bouctouche</City><Province>New Brunswick</Province><PostalCode>E4S</PostalCode><Country>Canada</Country></Address><AmmenitiesNearBy>Church, Marina, Shopping</AmmenitiesNearBy><LocationDescription>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praeteri</LocationDescription><ManagementCompany>DEMO Company</ManagementCompany><MunicipalId>DEMO Municipality</MunicipalId><OwnershipType>Freehold</OwnershipType><Photo><PropertyPhoto><SequenceId>1</SequenceId><LastUpdated>20/06/2017 02:38:43 PM</LastUpdated><PhotoLastUpdated>Tue, 20 Jun 2017 19:38:43 GMT</PhotoLastUpdated></PropertyPhoto></Photo><Price>12573.00</Price><PropertyType>Vacant Land</PropertyType><PublicRemarks>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praeteritis, inquit, gaudeo. Virtutibus igitur rectissime mihi videris et ad consuetudinem nostrae orationis vitia posuisse contraria. Non igitur de improbo, sed de callido improbo quaerimus, quali</PublicRemarks><TransactionType>For sale</TransactionType><UtilitiesAvailable><Utility><Type>Cable</Type><Description>Lorem ips</Description></Utility><Utility><Type>Telephone</Type><Description>Lorem ips</Description></Utility></UtilitiesAvailable><ViewType>View of water</ViewType><ZoningType>Residential</ZoningType></PropertyDetails></RETS-RESPONSE></RETS>

XSLT: https://pastebin.com/hiuT6cvp

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="no"/>
<xsl:template match="/">
<xsl:text>"ID;LastUpdated;ListingID;
 AgentName;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;;"</xsl:text>
    <xsl:text>&#13;&#10;</xsl:text>
    <xsl:for-each select = "RETS/RETS-RESPONSE/PropertyDetails"> 
        <xsl:value-of select = "@ID"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "@LastUpdated"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "ListingID"/>
        <xsl:apply-templates select = "AgentDetails"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "Board"/>
        <xsl:text>";"</xsl:text>
        <xsl:apply-templates select = "Business"/>
        <xsl:text>";"</xsl:text>
        <xsl:apply-templates select = "Building"/>
        <xsl:text>";"</xsl:text>
        <xsl:apply-templates select = "Land"/>
        <xsl:text>";"</xsl:text>
        <xsl:apply-templates select = "Address"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "Lease"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "LeasePerUnit"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "AmmenitiesNearBy"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "CommunityFeatures"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "Features"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "LocationDescription"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "ManagementCompany"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "MunicipalID"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "OwnershipType"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "ParkingSpaceTotal"/>
        <xsl:text>";"</xsl:text>
        <xsl:apply-templates select = "Photo"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "Price"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "PropertyType"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "PublicRemarks"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "RoadType"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "TransactionType"/>
        <xsl:text>";"</xsl:text>
        <xsl:apply-templates select = "UtilitiesAvailable"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "ViewType"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select = "ZoningType"/>
        <xsl:text>";"</xsl:text>
        <xsl:text>&#13;&#10;</xsl:text>
    </xsl:for-each>   
</xsl:template>

<xsl:template match="AgentDetails">
    <xsl:value-of select="Name"/>
    <xsl:text>";"</xsl:text>
    <xsl:apply-templates select="Phones"/>
    <xsl:text>";"</xsl:text>
    <xsl:apply-templates select="Office"/>
    <xsl:text>";"</xsl:text>
</xsl:template>

<xsl:template match="Office">
    <xsl:value-of select="@ID"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="@LastUpdated"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="Name"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="LogoLastUpdated"/>
    <xsl:text>";"</xsl:text>
    <xsl:apply-templates select="Office/Address"/>
    <xsl:text>";"</xsl:text>
    <xsl:apply-templates select="Phones"/>
    <xsl:text>";"</xsl:text>
    <xsl:apply-templates select="Websites"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="OrganizationType"/>
    <xsl:text>";"</xsl:text>
</xsl:template>

<xsl:template match="Office/Address">
    <xsl:value-of select="StreetAddress"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="AddressLine1"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="City"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="Province"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="PostalCode"/>
    <xsl:text>";"</xsl:text>
</xsl:template>

<xsl:template match="Websites">
    <xsl:for-each select="Website">
        <xsl:value-of select="@ContactType"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select="@WebsiteType"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>";"</xsl:text>
    </xsl:for-each>
</xsl:template>

<xsl:template match="Phones">
    <xsl:for-each select="Phone">
        <xsl:value-of select="@ContactType"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select="@PhoneType"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select="."/>
        <xsl:text>";"</xsl:text>
    </xsl:for-each>
</xsl:template>

<xsl:template match="Business">
    <xsl:value-of select="Franchise"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="Name"/>
    <xsl:text>";"</xsl:text>
</xsl:template>

<xsl:template match="Building">
    <xsl:value-of select="BathroomTotal"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="FireplacePresent"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="SizeInterior"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="Type"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="UtilityWater"/>
    <xsl:text>";"</xsl:text>
</xsl:template>

<xsl:template match="Land">
    <xsl:value-of select="SizeTotal"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="SizeTotalText"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="AccessType"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="Acreage"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="Amenities"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="Sewer"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="SizeIrregular"/>
    <xsl:text>";"</xsl:text>
</xsl:template>

<xsl:template match="Address">
    <xsl:value-of select="StreetAddress"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="AddressLine1"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="StreetNumber"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="StreetName"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="StreetSuffix"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="StreetDirectionSuffix"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="City"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="Province"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="PostalCode"/>
    <xsl:text>";"</xsl:text>
    <xsl:value-of select="Country"/>
    <xsl:text>";"</xsl:text>
</xsl:template>

<xsl:template match="Photo">
    <xsl:for-each select="PropertyPhone">
        <xsl:value-of select="SequenceId"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select="LastUpdated"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select="PhotoLastUpdated"/>
        <xsl:text>";"</xsl:text>
    </xsl:for-each>
</xsl:template>

<xsl:template match="UtilitiesAvailable">
    <xsl:for-each select="Utility">
        <xsl:value-of select="Type"/>
        <xsl:text>";"</xsl:text>
        <xsl:value-of select="Description"/>
        <xsl:text>";"</xsl:text>
    </xsl:for-each>
</xsl:template>

执行后 SSIS 未发布任何错误。但是 csv 文件仍然是空的。

【问题讨论】:

您确定您的应用程序支持 XSLT 2.0? 是的,它确实支持 XSLT 2.0。 :) 【参考方案1】:

你可以通过改变两件事来轻松地改进你的结果:

    &lt;xsl:text&gt;";"&lt;/xsl:text&gt; 更改为&lt;xsl:text&gt;;&lt;/xsl:text&gt;,因为xsl:text 不需要引号。 将xpath-default-namespace="urn:CREA.Search.Property" 添加到您的xsl:stylesheet 元素中。这将修复您的所有 XPath 表达式,因为 XPath 都缺少由&lt;RETS-RESPONSE xmlns="urn:CREA.Search.Property"&gt; 在您的 XML 中定义的默认命名空间,这会影响其所有子项。

所以您的 XSLT-2.0 代码应该如下所示:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xpath-default-namespace="urn:CREA.Search.Property">
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="no"/>

    <xsl:template match="/*:RETS">           
        <xsl:text>ID;LastUpdated;ListingID;AgentName;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</xsl:text>
        <xsl:text>&#13;&#10;</xsl:text>
        <xsl:for-each select = "RETS-RESPONSE/PropertyDetails"> 
            <xsl:value-of select = "@ID"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "@LastUpdated"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "ListingID"/>
            <xsl:apply-templates select = "AgentDetails"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "Board"/>
            <xsl:text>;</xsl:text>
            <xsl:apply-templates select = "Business"/>
            <xsl:text>;</xsl:text>
            <xsl:apply-templates select = "Building"/>
            <xsl:text>;</xsl:text>
            <xsl:apply-templates select = "Land"/>
            <xsl:text>;</xsl:text>
            <xsl:apply-templates select = "Address"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "Lease"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "LeasePerUnit"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "AmmenitiesNearBy"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "CommunityFeatures"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "Features"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "LocationDescription"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "ManagementCompany"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "MunicipalID"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "OwnershipType"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "ParkingSpaceTotal"/>
            <xsl:text>;</xsl:text>
            <xsl:apply-templates select = "Photo"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "Price"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "PropertyType"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "PublicRemarks"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "RoadType"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "TransactionType"/>
            <xsl:text>;</xsl:text>
            <xsl:apply-templates select = "UtilitiesAvailable"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "ViewType"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select = "ZoningType"/>
            <xsl:text>;</xsl:text>
            <xsl:text>&#13;&#10;</xsl:text>
        </xsl:for-each>   
    </xsl:template>

    <xsl:template match="AgentDetails">
        <xsl:value-of select="Name"/>
        <xsl:text>;</xsl:text>
        <xsl:apply-templates select="Phones"/>
        <xsl:text>;</xsl:text>
        <xsl:apply-templates select="Office"/>
        <xsl:text>;</xsl:text>
    </xsl:template>

    <xsl:template match="Office">
        <xsl:value-of select="@ID"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="@LastUpdated"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="Name"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="LogoLastUpdated"/>
        <xsl:text>;</xsl:text>
        <xsl:apply-templates select="Office/Address"/>
        <xsl:text>;</xsl:text>
        <xsl:apply-templates select="Phones"/>
        <xsl:text>;</xsl:text>
        <xsl:apply-templates select="Websites"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="OrganizationType"/>
        <xsl:text>;</xsl:text>
    </xsl:template>

    <xsl:template match="Office/Address">
        <xsl:value-of select="StreetAddress"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="AddressLine1"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="City"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="Province"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="PostalCode"/>
        <xsl:text>;</xsl:text>
    </xsl:template>

    <xsl:template match="Websites">
        <xsl:for-each select="Website">
            <xsl:value-of select="@ContactType"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select="@WebsiteType"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select="."/>
            <xsl:text>;</xsl:text>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="Phones">
        <xsl:for-each select="Phone">
            <xsl:value-of select="@ContactType"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select="@PhoneType"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select="."/>
            <xsl:text>;</xsl:text>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="Business">
        <xsl:value-of select="Franchise"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="Name"/>
        <xsl:text>;</xsl:text>
    </xsl:template>

    <xsl:template match="Building">
        <xsl:value-of select="BathroomTotal"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="FireplacePresent"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="SizeInterior"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="Type"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="UtilityWater"/>
        <xsl:text>;</xsl:text>
    </xsl:template>

    <xsl:template match="Land">
        <xsl:value-of select="SizeTotal"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="SizeTotalText"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="AccessType"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="Acreage"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="Amenities"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="Sewer"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="SizeIrregular"/>
        <xsl:text>;</xsl:text>
    </xsl:template>

    <xsl:template match="Address">
        <xsl:value-of select="StreetAddress"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="AddressLine1"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="StreetNumber"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="StreetName"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="StreetSuffix"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="StreetDirectionSuffix"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="City"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="Province"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="PostalCode"/>
        <xsl:text>;</xsl:text>
        <xsl:value-of select="Country"/>
        <xsl:text>;</xsl:text>
    </xsl:template>

    <xsl:template match="Photo">
        <xsl:for-each select="PropertyPhone">
            <xsl:value-of select="SequenceId"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select="LastUpdated"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select="PhotoLastUpdated"/>
            <xsl:text>;</xsl:text>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="UtilitiesAvailable">
        <xsl:for-each select="Utility">
            <xsl:value-of select="Type"/>
            <xsl:text>;</xsl:text>
            <xsl:value-of select="Description"/>
            <xsl:text>;</xsl:text>
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

它的输出应该接近你想要的。

【讨论】:

您好 zx485!我按照你说的做了,但现在它给我发送了一个错误,即“预期表达式结束,找到':'”。但是,我想当我从这个“ 嗨!只是一个更新,迈克尔能够解决这个问题。也感谢您的回答,因为我能够取得进步。【参考方案2】:

这里的问题是您的 XML 使用默认命名空间。

复杂之处在于默认命名空间应用于RETS-RESPONSE 元素,它不是根元素。

简单的解决方案是声明一个默认命名空间,但使用* 缩写来引用根RETS 元素。 IOW,改变:

<xsl:for-each select = "RETS/RETS-RESPONSE/PropertyDetails"> 

到:

<xsl:for-each select = "*/RETS-RESPONSE/PropertyDetails"> 

演示:https://xsltfiddle.liberty-development.net/gWvjQfT

【讨论】:

天哪,非常感谢。现在更有意义了。非常感谢迈克尔!也有美好的一天。

以上是关于SSIS - XML 任务未使用我创建的 XSLT-2.0 转换我的 XML 文件的主要内容,如果未能解决你的问题,请参考以下文章

在 SSIS 执行 SQL 任务中捕获错误行

在 SSIS 的脚本任务中使用变量

使用 XSLT 节点值的 XML 到 CSV 未显示

SSIS 脚本任务抛出未设置为对象实例的对象引用

SSIS 执行 SQL 查询任务找不到存储过程

使用XSLT输出未格式化的XML