[英]Remove Nodes from XML with XSLT
我有以下示例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>agent.lead.email@listhub.net</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>
我想从此XML文件中使用XSLT删除特定的节点,并最终获得代理,经纪,清单,照片和参与者。
这意味着,我想删除例如列表节点的某些部分。
<Listing>
<MarketingInfomation>
<VirtualTour>
<Videos>
<Franchise>
<Taxes>
<Expenses>
我一直在用这个XSLT弄乱它,但它不起作用..
<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>
要使用XSLT“删除节点”,只需将除那些节点以外的所有内容复制到输出中。 如果您要丢弃<Address>
节点及其内容,则示例XSLT ALMOST会做正确的事情。 您所缺少的是XML输入文档的名称空间。 你需要类似的东西
<xsl:template match="syndication:Address"
xmlns:syndication="http://rets.org/xsd/Syndication/2012-03"/>
当然,将xmlns:syndication
命名空间绑定移至<xsl:stylesheet>
元素,并使其继承,以便在整个样式表中根据需要都可用前缀,会更干净一些。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.