XSLT : Copy whole xml document discarding specific parent nodes -
i have :
<body> foo bar foo bar foo bar... <p>foo bar!</p> <div class="iwantyourcontent"> <p>baz</p> </div> </body>
i want output:
<body> foo bar foo bar foo bar... <p>foo bar!</p> <p>baz</p> </body>
i have managed content of node using :
<xsl:template match="/"> <xsl:apply-templates select="//x:div[@class = 'iwantyourcontent']"/> </xsl:template> <xsl:template match="//x:div[@class = 'iwantyourcontent']"> <body> <xsl:copy-of select="node()"/> </body> </xsl:template>
but i'm not able keep rest of document.
thanks helping.
the way sort of thing typically, identity template copies everything:
<xsl:template match="node()|@*" > <xsl:copy> <xsl:apply-templates select="node()|@*" /> </xsl:copy> </xsl:template>
and make template match items want skip over:
<xsl:template match="div[@class='iwantyourcontent']" > <xsl:apply-templates select="*" /> </xsl:template>
i.e. skip copy, because don't want div element copies, apply templates on further elements, because want copy descendants of div.
( if wanted skip contents entirely, leave template empty , have no content output @ all. )
Comments
Post a Comment