Skip to content

parents() doesn't match jQuery functionality when using selector #62

@jakejackson1

Description

@jakejackson1

Guidelines

Description of the bug

The jQuery API says that:

When multiple DOM elements are in the original set, the resulting set will be in reverse order of the original elements as well, with duplicates removed
If the selector is supplied, the elements will be filtered by testing whether they match it.

Initial testing shows the current querypath functionality doesn't correctly filter the results by the selector:

<?xml version="1.0"?>
<ns1:AmplifyResponse xmlns:ns1="http://amplify.hapax.com">
    <!--
    This document was retrieved from OpenAmplify.
    It is here to represent a moderately sized document for testing.
    -->
    <AmplifyReturn>
        <Demographics>
            <Age>
                <Name>Adult</Name>
                <Value>-0.007067</Value>
            </Age>
            <Gender>
                <Name>Neutral</Name>
                <Value>0.000000</Value>
            </Gender>
            <Education>
                <Name>Secondary</Name>
                <Value>2.000000</Value>
            </Education>
        </Demographics>
    </AmplifyReturn>
</ns1:AmplifyResponse>

Using the above XML, if you run qp($xml, 'Demographics > Age > Name')->parents('Demographics') you would expect to only get the <Demographics> node returned. Querypath currently returns <AmplifyReturn> and <ns1:AmplifyResponse> as well.

If you feed the same data into jQuery you only get the <Demographics> node returned.

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <script src="https://code.jquery.com/jquery-3.7.1.js"></script>
</head>
<body>

    <ns1:AmplifyResponse xmlns:ns1="http://amplify.hapax.com">
        <!--
        This document was retrieved from OpenAmplify.
        It is here to represent a moderately sized document for testing.
        -->
        <AmplifyReturn>
            <Demographics>
                <Age>
                    <Name>Adult</Name>
                    <Value>-0.007067</Value>
                </Age>
                <Gender>
                    <Name>Neutral</Name>
                    <Value>0.000000</Value>
                </Gender>
                <Education>
                    <Name>Secondary</Name>
                    <Value>2.000000</Value>
                </Education>
            </Demographics>
        </AmplifyReturn>
    </ns1:AmplifyResponse>

    <script>
        console.log(jQuery('Demographics > Age > Name').parents('Demographics'));
    </script>

</body>
</html>

https://api.jquery.com/parents/

QueryPath version

main

PHP Version and environment (server type, cli provider etc., enclosing libraries and their respective versions)

7.4

Minimal reproducible PHP+HTML snippet to replicate bug

As above

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions