Re: [xsl] Automatically generate xpath

Subject: Re: [xsl] Automatically generate xpath
From: "Jay Bryant" <jay@xxxxxxxxxxxx>
Date: Mon, 30 Jan 2006 16:23:02 -0600
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@xxxxxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
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

Current Thread