Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

How to remove a child node in xslt but only for a value-of element?

$
0
0

I have an xml doc like this :

<doc><article><photo><caption><p>     caption text<credit>photo copyright</credit></p></caption></photo></article></doc>

As you can see the "credit" tag is nested in the "p" tag…

I have an xsl code like this :

<xsl:template match="/doc"><caption><xsl:for-each select="article/photo"><xsl:value-of select="caption/p"/><xsl:text>&#xa;</xsl:text><xsl:value-of select="caption/p/credit"/></xsl:for-each></caption></xsl:template>

So I have an output like this :

<caption>    caption text photo copyright    photo copyright</caption>

What I would need is just removing the nested "credit" tag, and its content, but only for my first value-of element, as I need to keep it for my second value-of. So I would get this output :

<caption>    caption text    photo copyright</caption>

Which would be better as I don't want the photo copyright to be repeated… but I do need a line break between caption text and photo copyright…


Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>