0

I've got the following example XML..

http://app.listhub.com/syndication-docs/example.xml

    <Listings xmlns="http://rets.org/xsd/Syndication/2012-03" xmlns:commons="http://rets.org/xsd/RETSCommons"      xmlns:schemaLocation="http://rets.org/xsd/Syndication/2012-03/Syndication.xsd"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" listingsKey="2012-03-06T22:14:47"     version="0.96" versionTimestamp="2012-02-07T03:00:00Z" xml:lang="en-us">
    <Listing>
        <Address>...</Address>
        <ListPrice commons:isgSecurityClass="Public">234000</ListPrice>
        <ListPriceLow commons:isgSecurityClass="Public">214000</ListPriceLow>
        <AlternatePrices>...</AlternatePrices>
        <ListingURL>http://www.somemls.com/lisings/1234567890</ListingURL>
        <ProviderName>SomeMLS</ProviderName>
        <ProviderURL>http://www.somemls.com</ProviderURL>
        <ProviderCategory>MLS</ProviderCategory>
        <LeadRoutingEmail>[email protected]</LeadRoutingEmail>
        <Bedrooms>3</Bedrooms>
        <Bathrooms>8</Bathrooms>
        <PropertyType otherDescription="Ranch">Commercial</PropertyType>
        <PropertySubType otherDescription="Ranch">Apartment</PropertySubType>
        <ListingKey>3yd-SOMEMLS-1234567890</ListingKey>
        <ListingCategory>Purchase</ListingCategory>
        <ListingStatus>Active</ListingStatus>
        <MarketingInformation>...</MarketingInformation>
        <Photos>...</Photos>
        <DiscloseAddress>true</DiscloseAddress>
        <ListingDescription>...</ListingDescription>
        <MlsId>SOMEMLS</MlsId>
        <MlsName>Listing Exchange Group</MlsName>
        <MlsNumber>1234567890</MlsNumber>
        <LivingArea>2200</LivingArea>
        <LotSize>130680.000000</LotSize>
        <YearBuilt>1992</YearBuilt>
        <ListingDate>2012-01-06</ListingDate>
        <ListingTitle>Ranch, Ranch - Morgantown, WV</ListingTitle>
        <FullBathrooms>2</FullBathrooms>
        <ThreeQuarterBathrooms>3</ThreeQuarterBathrooms>
        <HalfBathrooms>2</HalfBathrooms>
        <OneQuarterBathrooms>1</OneQuarterBathrooms>
        <ForeclosureStatus>REO - Bank Owned</ForeclosureStatus>
        <ListingParticipants>...</ListingParticipants>
        <VirtualTours>...</VirtualTours>
        <Videos>...</Videos>
        <Offices>...</Offices>
        <Brokerage>...</Brokerage>
        <Franchise>...</Franchise>
        <Builder>...</Builder>
        <Location>...</Location>
        <OpenHouses>...</OpenHouses>
        <Taxes>...</Taxes>
        <Expenses>...</Expenses>
        <DetailedCharacteristics>...</DetailedCharacteristics>
        <ModificationTimestamp commons:isgSecurityClass="Public">2012-03-06T17:14:47-   05:00</ModificationTimestamp>
    </Listing>
</Listings>

From this XML file i want to use XSLT to remove particular nodes and end up with Agents, Brokerages, Listings, Photos and Participants.

This means, I would want to delete for example parts of the listing node.

<Listing> 
  <MarketingInfomation>
  <VirtualTour>
  <Videos>
  <Franchise>
  <Taxes>
  <Expenses>

I've been messing with this XSLT trying to get it but it doesn't work..

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://rets.org/xsd/Syndication/2012-03"version="1.0">
    <xsl:strip-space elements="*"/>
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="xmlns:Address"/>
</xsl:stylesheet>

1 Answer 1

1

To "remove nodes" with XSLT, simply copy everything except those nodes to the output. Your sample XSLT ALMOST does the right thing if you want to discard <Address> nodes and their content. What you've missed is that the XML input document is namespaced. You need something like

<xsl:template match="syndication:Address" 
              xmlns:syndication="http://rets.org/xsd/Syndication/2012-03"/>

Of course it would be a bit cleaner to move the xmlns:syndicationnamespace binding up to the <xsl:stylesheet> element, and let it be inherited so that prefix is available as needed throughout your stylesheet.

Sign up to request clarification or add additional context in comments.

5 Comments

(And you don't need the separate template for <a> attributes if it's going to do the same thing as the identity template, of course.)
was your comment cut off? Is it possible for you to edit my example XSLT to give me an idea of what you meant? As luck would have it currently im using XSLT to strip out all of the namespaces anyway since i'm loading this in with SSIS.
Sorry -- I was short one space on my code indentation. Fixed now.
i figured that part out, however is there a way to do that and strip out all of the namespaces at the same time?
Stripping out namespaces: Rather than use <xsl:copy>, use <xsl:element> to explicitly construct the output element using only the old element's localname.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.