我有一个XML文档,我需要删除特定的数据
xml文档的结构如下: -
<a>
<b select='yes please'>
<c d='text1' e='text11'/>
<c d='text2' e='text12'/>
<c d='text3' e='text13'/>
<c d='text4' e='text14'/>
<c d='text5' e='text15'/>
</b>
</a>
<a>
<b select='no thanks'>
<c d='text1' e='text21'/>
<c d='text3' e='text23'/>
<c d='text5' e='text25'/>
</b>
</a>
<a>
<b select='yes please'>
<c d='text1' e='text31'/>
<c d='text2' e='text32'/>
<c d='text3' e='text33'/>
<c d='text4' e='text34'/>
<c d='text5' e='text35'/>
</b>
</a>
<a>
<b select='no thanks'>
<c d='text4' e='text41'/>
<c d='text3' e='text43'/>
<c d='text5' e='text45'/>
</b>
</a>
Run Code Online (Sandbox Code Playgroud)
我只需要选择那些具有d attribute ='text1'和d attribute ='text4'的/ a/b元素组,一旦我识别出这些子文档,我想获得具有d属性值的e属性的值text5'
希望这清楚
干杯
DD
Kir*_*huk 35
您可以使用此XPath:
//a[b/c/@d = 'text1' and b/c/@d = 'text4']/b/c[@d = 'text5']/@e
Run Code Online (Sandbox Code Playgroud)
这将选择e='text15'与e='text35'第一和第三的a/b
XSLT:
<xsl:template match="//a[b/c/@d = 'text1' and b/c/@d = 'text4']/b/c[@d = 'text5']">
<xsl:value-of select="@e"/>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
我只需要选择那些具有d attribute ='text1'和d attribute ='text4'的/ a/b元素组,一旦我识别出这些子文档,我想获得具有d属性值的e属性的值text5'
希望这清楚
是的,很清楚XPath的翻译几乎是机械的
(: those /a/b element groups :) a/b
(: that have d attribute = 'text1' :) [c/@d='text1']
(: and d attribute = 'text4' :) [c/@d='text4']
(: and .. i want to get the value of the e attributes
with d attribute value 'text5' :) / c[@d='text5'] / @e
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
64541 次 |
| 最近记录: |