开发者

Select the value of the attribute

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

from the above xml i want 开发者_运维知识库to extract the "desc". keep in mind i have different tag names under the node.

Thanks for the help


How about a minimalist solution ?

//@desc

Or more precise

/Surcharge//@desc

Or even more precise

/Surcharge/*[self::Rentalplus|self::Gasket|self::WearandTear]/@desc


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

Exploits built-in rules. Result will be:

Rental plusSeals and gasketWear and Tear


Use:

/*/*/@desc

This selects all desc attributes of all children of the top element of the XML document.

Never use the // abbreviation when the structure of the document is well-known. Using the // abbreviation may result in significantly slow evaluation, because it causes traversal of the whole XML document.


Should be something like this:

//@desc

See syntax from the w3schools site http://www.w3schools.com/xsl/xpath_syntax.asp

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜