xsl-list
[Top] [All Lists]

Re: Automatically generate xpath

2006-01-30 15:23:02
Take a look at Saxon (my favorite XSLT processor). Saxon includes an
extension function called evaluate-node. That function reads an XPath
expression from a source document and then evaluates it at runtime - very
handy for this sort of thing.

HTH

Jay Bryant
Bryant Communication Services


----- Original Message ----- 
From: "Liron" <magilam(_at_)netvision(_dot_)net(_dot_)il>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Monday, January 30, 2006 3:19 PM
Subject: [xsl] Automatically generate xpath


Hello all,

I'm looing for some tool (an open source library would be better) that can
generate a xpath out of a set of xpaths with some rules like exclusion and
inclusion
I want to provide an example to what I mean. consider the following html:

<html>
   <body>
      <table>
         <tr><td><font>
         <a href="about:blank"><b>Text1</b></a>
         <a href="about:blank"><b>Text2</b></a>
         <a href="about:blank"><b>Text3</b></a>
         </font></td></tr>
         <tr><td><font>
         <a href="about:blank"><b>Text4</b></a>
         <a href="about:blank"><b>Text5</b></a>
         <a href="about:blank"><b>Text6</b></a>
         </font></td></tr>
       </table>
       <table>
         <tr><td><font>
         <a href="about:blank"><b>Text7</b></a>
         <a href="about:blank"><b>Text8</b></a>
         <a href="about:blank"><b>Text9</b></a>
         </font></td></tr>
         <tr><td><font>
         <a href="about:blank"><b>Text10</b></a>
         <a href="about:blank"><b>Text11</b></a>
         <a href="about:blank"><b>Text12</b></a>
         </font></td></tr>
      </table>
   </body>
</html>

I want to provide this tool the following xpaths:
/html/body/table[1]/tr[1]/td/font/a[1]/b/text() (this selects Text1) and
/html/body/table[2]/tr[2]/td/font/a[3]/b/text() (this selects Text12)
and get an output that looks something like:

/html/body/table/tbody/tr/td/font/a[((count(preceding-sibling::a) = 0) and
(ancestor::table[1][count(preceding-sibling::table)=0]) and
(ancestor::tr[1][count(preceding-sibling::tr)=0])) or
((count(preceding-sibling::a) = 2) and
(ancestor::table[1][count(preceding-sibling::table)=1]) and
(ancestor::tr[1][count(preceding-sibling::tr)=1]))]/b/text()

which will return me Text1 and Text12 (I have no idea how to make this
simpler, if someone know of a way, I'd appreciate it)

I'd also like to have the ability to exclude certain elements from a
supplied xpath in a kind of a reversed way.

If anyone knows of a solution or such a tool I'd really appreciate it

Thank you
Liron


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--