<Surcharge>
<Rentalplus desc="Rental plus">75.00</Rentalplus>
<Gasket desc="Seals and gasket">50.00</Gasket>
<WearandTear desc"Wear and Tear">100.00</WearandTear>
</Surcharge>
从上面的xml我想提取“desc”。请记住,我在节点下有不同的标签名称。
感谢您的帮助
答案 0 :(得分:2)
极简主义解决方案怎么样?
//@desc
或更精确
/Surcharge//@desc
甚至更精确
/Surcharge/*[self::Rentalplus|self::Gasket|self::WearandTear]/@desc
答案 1 :(得分:1)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/*">
<xsl:apply-templates select="*/@desc"/>
</xsl:template>
</xsl:stylesheet>
利用内置规则。结果将是:
Rental plusSeals and gasketWear and Tear
答案 2 :(得分:0)
答案 3 :(得分:0)
使用强>:
/*/*/@desc
这将选择XML文档顶部元素的所有子项的所有desc
属性。
当文档的结构众所周知时,切勿使用//
缩写。使用//
缩写可能会导致评估速度显着降低,因为它会导致遍历整个XML文档。