Search code examples
xmlcsvxsltssisxslt-2.0

SSIS - XML Task not converting my XML File using my created XSLT-2.0


I'm attempting to make an XML Task in SSIS which will convert an XML File to a CSV File using an XSLT. I've created the XSLT based on the samples online such as:

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

Make XSLT and XML Output to a XML File

But, I tried to run it in SSIS, it didn't work out. Can anybody check out what I did and point out where I went wrong.

So, I followed this link in terms of preparing the SSIS: http://blog.hoegaerden.be/2011/04/20/loading-complex-xml-using-ssis/

XML Sample Data: 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>

There were no errors posted by SSIS after executing. But the csv file was still empty.


Solution

  • The problem here is that your XML uses a default namespace.

    The complication is that the default namespace is applied at the RETS-RESPONSE element, which is not the root element.

    The simple solution is to declare a default namespace, but refer to the root RETS element using the * abbreviation. IOW, change:

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

    to:

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

    Demo: https://xsltfiddle.liberty-development.net/gWvjQfT