Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does XQ support concat, and if so, how in the hell does it work? #67

Closed
DCameronMauch opened this issue Jan 10, 2024 · 10 comments
Closed
Assignees
Labels
enhancement New feature or request

Comments

@DCameronMauch
Copy link

Problem Statement

Can't figure out how to use concat, if even supported. This is the best example I have found, and it produces no results: https://scrapfly.io/blog/how-to-join-values-in-xpath/

Expected Result

From the article above, I expect to see the output the articles says I should see.

@DCameronMauch DCameronMauch added the enhancement New feature or request label Jan 10, 2024
@DCameronMauch
Copy link
Author

DCameronMauch commented Jan 10, 2024

cameron@CameronMacBookPro latest % cat example.xml
<html>
  <div>
    <h2>Coffee</h2>
    <span data-currency="USD">4.69</span>
  </div>
</html>
cameron@CameronMacBookPro latest % cat example.xml | xq -x '//div/concat(h2, " - ", span, span/@data-currency)'
cameron@CameronMacBookPro latest %

@sibprogrammer
Copy link
Owner

Unfortunately, it doesn't work as intended. I'll take a look at how to workaround the problem.

@DCameronMauch
Copy link
Author

Thank you!

@sibprogrammer
Copy link
Owner

Now it's possible to use some popular functions. However, the support has some limitations. One of them is that the function will not work inside the selector but works well on the top level. It means you should use something like that:

$ cat example.xml | ./xq -x 'concat(//div/h2, " - ", //div/span, //div/span/@data-currency)'
Coffee - 4.69USD

@DCameronMauch
Copy link
Author

Awesome, thanks! I'll give that a whirl.

@DCameronMauch
Copy link
Author

DCameronMauch commented Jan 16, 2024

When will this be generally available? I tried it just now, with version 1.2.3, and still getting no results.

cameron@CameronMacBookPro latest % cat example.xml
<html>
  <div>
    <h2>Coffee</h2>
    <span data-currency="USD">4.69</span>
  </div>
</html>
cameron@CameronMacBookPro latest % cat example.xml | xq -x 'concat(//div/h2, " - ", //div/span, //div/span/@data-currency)'
cameron@CameronMacBookPro latest % xq -v
xq version 1.2.3 (2023-10-19T18:59:37Z, 2842ec90a2d8143dd90211b083ace7325e6a3a8f)

@sibprogrammer
Copy link
Owner

The issue was addressed in the master branch, which points to 1.2.4 (see https://github.com/sibprogrammer/xq/blob/master/version) It is not released yet. But I think I'll release it today or tomorrow.

@DCameronMauch
Copy link
Author

Thanks again!

@DCameronMauch
Copy link
Author

FYI - Confirmed working

cameron@CameronMacBookPro latest % cat example.xml | xq -x 'concat(//div/h2, " - ", //div/span, //div/span/@data-currency)'
Coffee - 4.69USD

@andig
Copy link

andig commented Mar 31, 2024

Is this also possible when using CSS selectors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants