使用这个单一的 XPath 表达式:
translate(
concat(//span[@itemprop = 'price']/text()[normalize-space()],
//span[@itemprop = 'price']/span[@class='offer_price_fraction']
),
',',
'.'
)
基于 XSLT 的验证:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:copy-of select=
"translate(
concat(//span[@itemprop = 'price']/text()[normalize-space()],
//span[@itemprop = 'price']/span[@class='offer_price_fraction']
),
',',
'.'
)"/>
</xsl:template>
</xsl:stylesheet>
当将此转换应用于此 XML 文档时:
<span itemprop="price" class="offer_price">
<span class="currency">\u20ac</span>
16<span class="offer_price_fraction">,95</span>
</span>
对 XPath 表达式求值,并将该求值的结果复制到输出中:
16.95