2009-12-08 18 views
0

讓我們假設我們有XML:如何用xslt去除部分附加的xml?

 
<tag1> text <tag2> { 
    <tag3> name1 </tag3>:<tag4><val>value1</val>;</tag4> 
    <tag3> name2 </tag3>:<tag4><val>value2</val>;</tag4> 
}</tag2> </tag1> 

如何刪除整條生產線用XSLT名1和值1(從<TAG3>到</TAG4 >)?

我沒有問題來移除tag3和tag4,但這個冒號(':')字符對我來說是有問題的。

+0

這基本上和你自己以前的問題一樣:http://stackoverflow.com/questions/1825058/how-to-create-xslt-transformation-for-srcml。你還沒有評論我的答案。 – Tomalak 2009-12-08 15:39:27

回答

0

這是一個非常醜陋的解決方案,但它的工作原理。 這是醜陋的,因爲條件必須重複3次。必須有一個更簡單的方法來做到這一點。

<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>