Jump to content

Delete elements via XSL


JDS

Recommended Posts

Posted

Hi all,I'm new to XSL and would like to know whether it is possible to remove certain data from an XML via XSL.I have the following structure:

<bookExtract><listingContent advertName="A" bgColor="" boxColor="" boxType="" code="10 00 123456 x     KM" id="497590000"><span></span></listingContent><listingContent advertName="Be" bgColor="" boxColor="" boxType="" code="10 00 123456 x     KM" id="497610000"><span></span></listingContent><listingContent advertName="DB" bgColor="" boxColor="" boxType="" code="10 00 123456 x     RL" id="497630000"><span></span></listingContent></bookExtract>

I would like to get rid of all

<listingContent>...</listingContent>

where de code from <listingContent> contains KM"Is it possible to achieve it via XSL?If so how can this then be done?Thanks for the effort,John

Posted
<xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0">  <xsl:template match="@* | node()">	 <xsl:copy>		<xsl:apply-templates select="@* | node()"/>	 </xsl:copy>  </xsl:template>  <xsl:template match="listingContent[contains(@code, 'KM')]"/></xsl:stylesheet>

copies everything but those 'listingContent' elements where the 'code' attribute value contains 'KM'.

Posted

Thank you Martin for your quick answer.On the xml I added in the topic it worked but the actual XML has a bigger structure. Perhaps I should have added this one to start with. When I run your script to this, it doesn't seem to work anymore.Could you take a look at the following code? Now this is the complete structure.Thanks again.

<bookExtract> <sectionList><classifiedSection><classificationList><classification><name>A</name><contentList><listingContent advertName="A" bgColor="" boxColor="" boxType="" code="10 00 123456 x     KM" id="497590000"><span></span></listingContent><listingContent advertName="Be" bgColor="" boxColor="" boxType="" code="10 00 123456 x     KM" id="497610000"><span></span></listingContent><listingContent advertName="DB" bgColor="" boxColor="" boxType="" code="10 00 123456 x     RL" id="497630000"><span></span></listingContent></contentList></classification><name>B</name><classification><contentList><listingContent advertName="A" bgColor="" boxColor="" boxType="" code="10 00 678654 x     KM" id="497590000"><span></span></listingContent><listingContent advertName="Be" bgColor="" boxColor="" boxType="" code="10 00 678654 x     KM" id="497610000"><span></span></listingContent><listingContent advertName="DB" bgColor="" boxColor="" boxType="" code="10 00 678654 x     RL" id="497630000"><span></span></listingContent></contentList></classification></classificfationList></classifiedSection></sectionList></bookExtract>

Posted

Martin,I just found out that there was a reference to an xsd file, and that's the reason why It didn't work.Thanks again.Best Regards,John

Thank you Martin for your quick answer.On the xml I added in the topic it worked but the actual XML has a bigger structure. Perhaps I should have added this one to start with. When I run your script to this, it doesn't seem to work anymore.Could you take a look at the following code? Now this is the complete structure.Thanks again.
<bookExtract> <sectionList><classifiedSection>...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...