XPath ignore span -


i have html contains tags below:

<div id="snt">text1</div> <div id="snt">text2</div> <div id="snt">textbase1<span style='color: #efffff'>text3</span></div> <div id="snt">textbase2<span style='color: #efffff'>text4</span></div> 

how can all texts included in <div> tags using xpath, ignoring span fields?

i.e.:

text1   text2   textbase1text3   textbase2text4    

this cannot specified single xpath 1.0 expression.

you need first select relevant div elements:

//div[@id='snt] 

then each selected node string node:

string(.) 

in xpath 2.0 can specified single expression:

//div[@id='snt]/string(.) 

xslt - based verification:

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform">  <xsl:output method="text"/>   <xsl:template match="div[@id='snt']">      <xsl:copy-of select="string()"/> ========      </xsl:template> </xsl:stylesheet> 

when xslt 1.0 transformation applied on following xml document (the provided xml fragment, wrapped single top element):

<t>     <div id="snt">text1</div>     <div id="snt">text2</div>     <div id="snt">textbase1<span style='color: #efffff'>text3</span></div>     <div id="snt">textbase2<span style='color: #efffff'>text4</span></div> </t> 

the relevant div elements selected (matched) , processed specified template, in string(.) xpath expression evaluated , result copied output:

    text1 ========          text2 ========          textbase1text3 ========          textbase2text4 ========     

and xpath 2.0 expression:

<xsl:stylesheet version="2.0"     xmlns:xsl="http://www.w3.org/1999/xsl/transform">     <xsl:output method="text"/>   <xsl:template match="/">      <xsl:copy-of select="//div[@id='snt']/string(.)"/>  </xsl:template> </xsl:stylesheet> 

when xslt 2.0 transformation applied on same xml document (above), xpath 2.0 expression evaluated , result (four strings) copied output:

text1 text2 textbase1text3 textbase2text4 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -