X Tutup
Skip to content
/ lxml Public

Make .nsmap available in XSLT extensions.#269

Merged
scoder merged 1 commit intolxml:masterfrom
adelton:extension-nsmap
Apr 5, 2019
Merged

Make .nsmap available in XSLT extensions.#269
scoder merged 1 commit intolxml:masterfrom
adelton:extension-nsmap

Conversation

@adelton
Copy link

@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.

return funicode(self._c_node.ns.prefix)
return None

property nsmap:
Copy link
Member

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

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 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
Author

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup