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

Make .nsmap available in XSLT extensions. #269

Merged
merged 1 commit into from Apr 5, 2019
Merged

Conversation

@adelton
Copy link
Contributor

@adelton adelton commented Aug 9, 2018

When adding namespaced elements/attributes in execute of XSLT extension element, new xmlns declaration is generated with prefix ns0. At the same time it does not seem to be possible to figure out what are the existing namespaces and prefixes in the input_node, resulting in

AttributeError: 'lxml.etree._ReadOnlyElementProxy' object has no attribute 'nsmap'

This patch makes it possible to see the namespace map.

@@ -290,6 +290,26 @@ cdef class _ReadOnlyElementProxy(_ReadOnlyProxy):
return funicode(self._c_node.ns.prefix)
return None

property nsmap:
Copy link
Member

@scoder scoder Aug 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a copy of _Element.nsmap, so the dict building should go into a shared helper function.

extensions = { ('extns', 'show-nsmap') : MyExt() }

result = tree.xslt(style, extensions=extensions)
self.assertEqual(etree.tostring(result, pretty_print=True), """\
Copy link
Member

@scoder scoder Aug 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to compare to a bytes literal to work in Py3.

@scoder
Copy link
Member

@scoder scoder commented Aug 9, 2018

Documentation and docstring missing. Changelog entry would also be nice.

@scoder scoder added the feature label Aug 9, 2018
@adelton
Copy link
Contributor Author

@adelton adelton commented Apr 5, 2019

I'm afraid I won't be able to address the comments in the review in foreseeable future. Would you prefer this pull request closed, or left open, for the off chance that someone else in the community has the need and time to polish this?

@scoder scoder merged commit 9b9136b into lxml:master Apr 5, 2019
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants