Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] removing nodes according to attibute value

From: "Michael Kay" <mike@------------>
To:
Date: 11/1/2005 4:07:00 PM
> I'm trying to remove all elements that have a specific 
> attribute containing 
> some characters.

Start with an identity template that copies everything:

<xsl:template match="*">
  <xsl:copy><xsl:copy-of select="@*"/><xsl:apply-templates/></xsl:copy>
</xsl:template>

> See example below... I need to remove all 
> /ApplicationCatalogue/Category/Product that have @code 
> starting with TT.

Add a template rule that doesn't copy such elements:

<xsl:template match="Product[starts-with(@code, 'TT')]"/>


> It has to be generic as the xml provided can have more attributes & 
> elements.
> Also I would need to remove the 
> /ApplicationCatalogue/Category if it doesn't 
> have any Product left after the removal

Add another template rule:

<xsl:template match="Category[not(Product[not(starts-with(@code, 'TT))])]"/>

Michael Kay
http://www.saxonica.com/


> Any idea ??? Thanx a million ...
> 
> 
> <ApplicationCatalogue name="42222_downloads_stg">
>  <Category name="2_live_crew" description="2_live_crew">
>   <Product code="TT050089891" position="0">
>    <Alias isDefault="true">
>     <Name>89891</Name>
>     <Extra></Extra>
>    </Alias>
>    <Attributes>
>     <OTAobject_otaother_namepreview>Getting 
> High</OTAobject_otaother_namepreview>
>     <OTAobject_otaother_author>2 Live Crew</OTAobject_otaother_author>
>    </Attributes>
>   </Product>
>   <Product code="PP050089892" position="0">
>    <Alias isDefault="true">
>     <Name>89892</Name>
>     <Extra></Extra>
>    </Alias>
>    <Attributes>
>     <OTAobject_otaother_namepreview>Pimp Of The 
> Year</OTAobject_otaother_namepreview>
>     <OTAobject_otaother_author>2 Live Crew</OTAobject_otaother_author>
>    </Attributes>
>   </Product>
>   <Product code="PP050089893" position="0">
>    <Alias isDefault="true">
>     <Name>89893</Name>
>     <Extra></Extra>
>    </Alias>
>    <Attributes>
>     <OTAobject_otaother_namepreview>Shake Junk 
> Queen</OTAobject_otaother_namepreview>
>     <OTAobject_otaother_author>2 Live Crew</OTAobject_otaother_author>
>    </Attributes>
>   </Product>
>   <Product code="TT050089894" position="0">
>    <Alias isDefault="true">
>     <Name>89894</Name>
>     <Extra></Extra>
>    </Alias>
>    <Attributes>
>     <OTAobject_otaother_namepreview>Stop 
> Playin</OTAobject_otaother_namepreview>
>     <OTAobject_otaother_author>2 Live Crew</OTAobject_otaother_author>
>    </Attributes>
>   </Product>
>  </Category>
> </ApplicationCatalogue>


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent