943,539 Members | Top Members by Rank

Ad:
Aug 29th, 2009
-1

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

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
csplrj is offline Offline
1 posts
since Dec 2006
Sep 6th, 2009
0

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

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>
Reputation Points: 22
Solved Threads: 11
Junior Poster
fpmurphy is offline Offline
144 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in XML, XSLT and XPATH Forum Timeline: Xpath Corelate Parent With Variable number Of Children
Next Thread in XML, XSLT and XPATH Forum Timeline: [PHP] How to change a value with XPath





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC