Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Removing an element but keeping its child nodes with XSL [Thread Next] Re: Removing an element but keeping its child nodes with XSLTo: NULL Date: 11/17/2009 5:40:00 PM Ryan Gomez wrote:
> How do I go about transforming the XML document below into result.xml? Basically what I'm aiming for is to remove one of the element but keeping the children. So I would like to remove the <Location> element but keep the <City> element (the <City> element being the child element of <Location>). Any pointers would be greatly appreciated. Thanks!
>
> <User>
>
> <TITLE>Mrs</TITLE>
>
> <INITIALS>D</INITIALS>
>
> <FIRST_NAME>Doris</FIRST_NAME>
>
> <LAST_NAME>Smith</LAST_NAME>
>
> <Location>
>
> <City>London</City>
>
> </Location>
>
> </User>
>
> ** How do I transform this to**
>
>
> <User>
>
> <TITLE>Mrs</TITLE>
>
> <INITIALS>D</INITIALS>
>
> <FIRST_NAME>Doris</FIRST_NAME>
>
> <LAST_NAME>Smith</LAST_NAME>
>
> <City>London</City>
>
> </User>
You need two templates, one is the identity transformation template
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
then a second template for the 'Location' elements that simply processes
any child nodes
<xsl:template match="Location">
<xsl:apply-templates/>
</xsl:template>
--
Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
