xpath: Is there a way to get all the children's text in xpath
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 span
s 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>
精彩评论