Note that there are some explanatory texts on larger screens.

plurals
  1. POTransform Javascript XPath in valid PHP query() XPath | normalize JS XPath --> PHP
    primarykey
    data
    text
    <p>This is valid XPath in Javascript:</p> <pre><code>id("priceInfo")/div[@class="standardProdPricingGroup"]/span[1] </code></pre> <p>And this turned into valid PHP XPath to be used with DOMXPath->query() is</p> <pre><code>//*[@id="priceInfo"]//div[@class="standardProdPricingGroup"]//span[1] </code></pre> <ol> <li>do you know any libraries or custom components that already do this transformation? </li> <li>do you know available documentation that lists the two syntax differences?</li> </ol> <p>My main concern is that there could be a lot of differences, and I am looking to identify these differences, and I have problems to identify these. </p> <p>The question could be put also in different way: <strong>Since Javascript can have different valid XPath formats, how to normalize them to work with the PHP.</strong></p> <p>One of the updates also mention that the id() function is valid XPath if there is a valid DTD that contains this definition. I don't have power over the input DTD, and if there is a way to find a solution that works without any specific DTD it would be awesome.</p> <p><strong>Update:</strong></p> <p>I want to transform the first format into the second with an algorithm. My input is the first one and not the second one. Can't change this.</p> <p>As @Nison Maël pointed out, the 2nd format is valid Javascript XPath as presented here: <a href="http://jsbin.com/elatum/2/edit">http://jsbin.com/elatum/2/edit</a> this unfortunately just adds to the problem of Javascript XPath "fragmentation".</p> <p>@salathe pointed out that the valid Javascript XPath query works fine in PHP if the input documented has valid DTD ( @Dimitre Novatchev mentioned this in a comment, but overlooked the importance). Unfortunately I don't have control of the input DTD, so now I have to investigate a way to overcome this, or to find a solution that works even without valid DTD.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload