开发者

How to remove part of attached xml with xslt?

开发者 https://www.devze.com 2022-12-13 08:42 出处:网络
Lets assume we have xml: <tag1> text <tag2> { <tag3> name1 </tag3>:<tag4><val>value1</val>;</tag4>

Lets assume we have xml:

<tag1> text <tag2> {
  <tag3> name1 </tag3>:<tag4><val>value1</val>;</tag4>
  <tag3> name2 <开发者_C百科/tag3>:<tag4><val>value2</val>;</tag4>
}</tag2> </tag1>

How to remove whole line with name1 and value1 (from <tag3> to </tag4>) with xslt?

I have no problem to remove tag3 and tag4 but this colon (':') character is problematic for me.


Here is a solution which is very ugly but it works. It's ugly because the condition has to be repeated 3 times. There must be a simpler way to do that.

<xsl:template match="tag3[text()=' name1 ' and following-sibling::tag4[val/text()='value1']]"/>
<xsl:template match="text()[preceding-sibling::tag3[text()=' name1 '] and following-sibling::tag4/val[text()='value1']]" />
<xsl:template match="tag4[val/text()='value1' and preceding-sibling::tag3[text()=' name1 ']]" />
<xsl:template match="@* | node()">
    <xsl:copy>
        <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
</xsl:template>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号