patrizio.trinchini@googlemail.com wrote:
Quote:
Hi,
>
how can remove sibling elements based on the value of an attribute ?
>
For instance, gven the XML document:
>
<root>
<parentElment>
<testElement name="A">
<removableElement/>
</parentElment>
<parentElment>
<testElement name="B">
<removableElement/>
</parentElment>
</root>
>
I would write a XSLT transformer that implements the following rule:
>
IF testElement[@name='A'] THEN <remove sibling element
removableElement>
>
so that the resultng XML document looks lke the following:
>
<root>
<parentElment>
<testElement name="A">
</parentElment>
<parentElment>
<testElement name="B">
<removableElement/>
</parentElment>
</root>
Think of it the other way round: if the attribute value is not A,
then process the following sibling:
<xsl:template match="testElement">
<testElement>
<xsl:if test="@name!='A' and following-sibling::removableElement">
<removableElement/>
</xsl:if>
</testElement>
</xsl:template>
///Peter