Identity transform, remove one filtered element, not working
Posted: Sun Aug 19, 2012 7:50 pm
Hi, all,
I'm a newbie to XSLT and a non-programmer (unfortunately). I'm trying to copy all of a large XML document into a new XML document, except I want to remove one element and its children if one of its child elements contains a specific value.
Source XML:
I need to remove all <Name-Role> elements and children when /role="INR".
I thought two simple templates would do the trick, but the Name-Role elements and children were copied to the result file -- no idea why.
My failed attempt:
Any help deeply appreciated!
Bingley
I'm a newbie to XSLT and a non-programmer (unfortunately). I'm trying to copy all of a large XML document into a new XML document, except I want to remove one element and its children if one of its child elements contains a specific value.
Source XML:
Code: Select all
<rootElement>
<TitleWork>
...
<roles>
<Name-Role>
<party xl:href="/Name/key/2708 xl:title="Smith, John"></party>
<principalRole>N</principalRole>
<role xl:href="/Code/key/ROLE//INE" l:title="Interviewee">INE</role>
</Name-Role>
<Name-Role>
<party xl:href="/Person/key/279613-1" xl:title="Johnson, Joe"></party>
<principalRole>N</principalRole>
<role xl:href="/Code/key/ROLE//INE" xl:title="Interviewee">INE</role>
</Name-Role>
<Name-Role>
<party xl:href="/Person/key/373022-1" xl:title="McColl, Steven"></party>
<principalRole>N</principalRole>
<role xl:href="/Code/key/ROLE//INR" xl:title="Interviewee">INR</role>
</Name-Role>
</roles>
...
</TitleWork>
<TitleWork> ...
</RootElement>
I thought two simple templates would do the trick, but the Name-Role elements and children were copied to the result file -- no idea why.
My failed attempt:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:xl="http://www.w3.org/TR/xlink">
<xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="no"></xsl:output>
<xsl:template match="/|@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"></xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="//Name-Role[role='INR']"/>
</xsl:stylesheet>
Any help deeply appreciated!
Bingley