开发者

xpath: Is there a way to get all the children's text in xpath

开发者 https://www.devze.com 2022-12-15 04:52 出处:网络
I\'m using the xpath engine on Firefox. I have html: <span> <b>prefix one</b> not bold part

I'm using the xpath engine on Firefox. I have html:

<span>
   <b>prefix one</b> not bold part
</span>
<span>
   prefix two not bold part
</span>

I want all the spans that have child text that start with "prefix one".

I tried the xpath:

//span[starts-with(child::text(), "prefix one")]

but this doesn't开发者_Python百科 work because the b tag is interfering. How do you solve this?

thanks


If you know that spans is not nested into other spans you can try this:

//span[ starts-with( descendant-or-self::*/text(),"prefix one" ) ]

descendant-or-self::*/text(), should return all text nodes which are in this subtree. I don't know how starts-with() exactly works but I suppose when some of text() nodes in subtree starts with "prefix one" that condition is true


<xsl:template match="span">
<xsl:if test="contains(.,'prefix one')">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:template>
0

精彩评论

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