XPath expression for <td> tag having "Type" as textContent in any of its childNodes

Please support our XML, XSLT and XPATH advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2006
Posts: 1
Reputation: csplrj is an unknown quantity at this point 
Solved Threads: 0
csplrj csplrj is offline Offline
Newbie Poster

XPath expression for <td> tag having "Type" as textContent in any of its childNodes

 
-1
  #1
Aug 29th, 2009
I have a HTML document in which there is a <td> tag
In this td tag the TextContent is equal to "Type"
It is not neccessary that the td tag directly has content,it may have content in the subtags.

The "Type" stuff may be enclosed in between the spaces

What will be the XPath expression for the same?

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <td align="left" style="background-color:#648190;"><span style="color:#ffffff;font-family:arial;font-size:small;"><b> Type</b></span></td>


Thanks in advance

CSJakharia
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 95
Reputation: fpmurphy is an unknown quantity at this point 
Solved Threads: 5
fpmurphy fpmurphy is offline Offline
Junior Poster in Training

Re: XPath expression for <td> tag having "Type" as textContent in any of its childNod

 
0
  #2
Sep 6th, 2009
Assuming the following example HTML file as input
XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <html>
  2. <head></head>
  3. <body>
  4. <td align="left" style="background-color:#648190;"><span style="color:#ffffff;font-family:arial;font-size:small;"><b> Type</b></span></td>
  5. <td align="left" style="background-color:#648190;"> Value</td>
  6. </body>
  7. </html>
The following stylesheet will output the node-set containing the string "Type" in any text node.
XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  3.  
  4. <xsl:output method="xml"/>
  5.  
  6. <xsl:template match="/html//td">
  7. <xsl:if test=".//text()[contains(., 'Type')]">
  8. <xsl:copy-of select="." />
  9. </xsl:if>
  10. </xsl:template>
  11.  
  12. <xsl:template match="/">
  13. <xsl:apply-templates select="/html//td" />
  14. </xsl:template>
  15.  
  16. </xsl:stylesheet>
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC