This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add concat functionality to ElementTree xpath find
Type: enhancement Stage: patch review
Components: Library (Lib), XML Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eli.bendersky, jjolly, matrixise, ned.deily, scoder
Priority: normal Keywords: patch

Created on 2018-01-01 19:19 by jjolly, last changed 2022-04-11 14:58 by admin.

Files
File name Uploaded Description Edit
etree-concat.patch jjolly, 2018-01-01 19:19 Patch to add concat functionality to predicates in etree
Pull Requests
URL Status Linked Edit
PR 5251 open jjolly, 2018-01-20 17:53
Messages (7)
msg309344 - (view) Author: John Jolly (jjolly) * Date: 2018-01-01 19:19
The current implementation of the xpath specification in ElementTree does not allow for predicates that may contain both an apostrophe and a quote. Either one or the other is allowed, but escaping (either string escaping using the backslash or html escaping) is not supported.

A simple solution would be to implement the xpath concat function for predicates. This would allow the combination of quote types in the predicate. Attached is a proposed patch for this fix.
msg311259 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2018-01-30 09:39
as explained on the PR, maybe you could add in the documentation.

..versionadded:: 3.7
    Support of the XPath concat function

but maybe your PR is too late because 3.7 starts to be in the frozen period for the features.
msg311273 - (view) Author: John Jolly (jjolly) * Date: 2018-01-30 14:29
I understand that the feature is likely too late, but I do not want it to get lost. Is there any way to make certain this feature is accepted for the next release? Do I just select the 3.8 version for this issue?
msg311277 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2018-01-30 15:44
I think (but not sure) that your feature will be included in 3.8 because 3.7 has been frozen today :/

@ned do you think you could integrate this functionality in 3.7 or 3.8 ?
msg311399 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-02-01 02:26
Sorry, I think this qualifies as a new feature and thus needs to go in 3.8.  Plus it should get a wider review from those with ET experience.  Perhaps @scoder would be willing go take a look.
msg313959 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2018-03-16 16:58
I can't see why this should be restricted to attribute values and not text content in general. Therefore, I would suggest adding general support for functions, and making this only a special case. Otherwise, this would only solve a very niche problem, and would require pretty much a rewrite in order to extend it into the "obvious" direction.
msg366247 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2020-04-12 13:29
I think the use case of quote escaping is too niche for a feature like concat(), where I (at least) would expect to be able to dynamically concatenate text content, not just constant strings.

There seem to be at least a few alternatives to the usage of concat():

https://stackoverflow.com/questions/12403870/how-to-escape-single-quote-in-xslt-substring-function

https://sqa.stackexchange.com/questions/26341/how-to-write-xpath-if-i-have-apostrophe-in-my-xpath-element

I think we should either implement concat() completely, or provide a different way to solve the concrete problem at hand.
History
Date User Action Args
2022-04-11 14:58:56adminsetgithub: 76657
2020-04-12 13:29:36scodersetmessages: + msg366247
versions: + Python 3.9, - Python 3.8
2018-03-16 16:58:54scodersetmessages: + msg313959
components: + XML
2018-02-01 02:26:38ned.deilysetnosy: + scoder

messages: + msg311399
versions: - Python 3.7
2018-01-30 15:44:28matrixisesetversions: + Python 3.7
2018-01-30 15:44:21matrixisesetversions: + Python 3.8, - Python 3.7
2018-01-30 15:44:17matrixisesetnosy: + ned.deily
messages: + msg311277
2018-01-30 14:29:48jjollysetmessages: + msg311273
2018-01-30 09:39:50matrixisesetnosy: + matrixise
messages: + msg311259
2018-01-20 17:53:34jjollysetstage: patch review
pull_requests: + pull_request5098
2018-01-12 18:37:36jjollysetnosy: + eli.bendersky
2018-01-01 19:19:06jjollycreate