Remove group levels
Posted: Wed Mar 14, 2012 5:21 pm
I have XML that contains elements that contain other elements but not values, they all have 'Group' in the element name. Is it possible to remove the tags that contain 'Group'; found the function syntax:
not(contains(name(),'Group') - i'm not sure where it would go?
Here is my current xsl:
not(contains(name(),'Group') - i'm not sure where it would go?
Code: Select all
<my:BestPracticeGroup>
<my:BPRepeatSection>
<my:BPDetails>Complete central line insertion checklist in real time</my:BPDetails>
<my:ActionsGroup>
<my:ActionsTable>
my:DateImplementBP>2012-02-02</my:DateImplementBP>
<my:DateCompleteBP>2012-03-02</my:DateCompleteBP>
</my:ActionsTable>
<my:ActionsTable>
</my:ActionsTable>
</my:ActionsGroup>
</my:BPRepeatSection>
</my:BestPracticeGroup>
Code: Select all
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no"/>
<xsl:template match="/|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>
</xsl:stylesheet>