Sumathi
Sumathi

Reputation: 83

XSLT - remove duplicate parent element

My Input XML is like below,

<part type="content">
<part type="content">
<title>PART IFundamentals and Basics</title>
................
</part>
<part type="content">
<title>PART IISkin and Soft Tissue</title>
................
</part>
<part type="content">
<title>PART IIIHead and Neck<target id="p003"/><target id="page215"/></title>
................
</part>
</part>

Output should be change as,

<part type="content">
<title>PART IFundamentals and Basics</title>
................
</part>
<part type="content">
<title>PART IISkin and Soft Tissue</title>
................
</part>
<part type="content">
<title>PART IIIHead and Neck<target id="p003"/><target id="page215"/>    </title>
................
</part>

My XSLT is like,

<xsl:template match="part[@type='content']/part[@type='content']">        
<xsl:apply-templates />        
</xsl:template>  

While using above xslt, "part" element is getting remove from "Part II" parent elements. Could you please guide us.

Upvotes: 0

Views: 57

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167436

Change <xsl:template match="part[@type='content']/part[@type='content']"> to <xsl:template match="part[@type='content'][part[@type='content']]"> and make sure the identity transformation or your other templates copy the rest of the nodes.

Upvotes: 1

Related Questions