开发者

XSL elements inheriting namespace dynamically

I am writing a stylesheet that is ultimately combined (via code) with varying other stylesheets outside of my control and scope, before transforming XML.

I am writing 'xsl:element's within templates, however I am not aware if the other templates I do not control have already defined a namespace attached to an ancestor element (i.e. xmlns="blah").

In this circumstance, if I don't specify the namespace on the xsl:element I'll receive an xmlns="", putting this element back in no namespace. However I don't want this to occur, but I am not able specifically to set the namespace to a literal value, nor am I able to set the stylesheet default namespace.

I have seen numerous posts trying to remove xmlns="", but I don't feel any solutions were appropriate for this situation. Most related to setting namespaces on all nodes, setting up defaults, or excluding result prefixes for #defa开发者_如何学Pythonult.

I am using XSLT 1.0 and I am happy to search ancestors for the closest element that has a namespace defined other than no namespace, and using this as the element namespace. Unfortunately I've not managed to achieve this, thus any help is appreciated. Thanks, apologies if I've missed an existing solution.


Interesting problem. Your requirement is to create an element whose namespace is the same as that of its parent element in the result tree, which you don't know statically. The solution is exactly the same as if you wanted to create an element whose local name is the same as that of its parent element in the result tree: as you might expect, the URI and local parts of the element name have equal weight in XSLT. (The language has little sympathy for people who want to treat namespaces as mere decorative adornment.) In both cases the solution is to pass the unknown information as a parameter to the template that creates the element.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜