Re: [xsl] Help namespacing an attribute

Subject: Re: [xsl] Help namespacing an attribute
From: "G. Ken Holman g.ken.holman@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 20 Sep 2017 17:11:08 -0000
At 2017-09-20 16:57 +0000, Bridger Dyson-Smith bdysonsmith@xxxxxxxxx wrote:
I'm having some trouble getting a namespace attached to an attribute -- instead the attribute's namespace is getting attached to the element.

Namespaces are only ever attached to elements. They are never attached to attributes. Attributes use the namespaces that are attached to elements in the ancestry.


I worked up a minimized example that worked the way I expected it to work, but when trying to implement my expectations I'm failing.

I'm roundly convinced that this doesn't work in my real data

Your "real work" results are acceptable and appropriate, I see nothing wrong.


because I'm missing something with namespaces but I'm not sure what.

Probably that attributes use namespaces attached to elements in the ancestry.


Despite trying both serialization methods (literal and programmatic), both return the same result.

I'm using XSLT 2.0, but the application is using Saxon 8.7.

I'm looking for

<accessCondition type="use and reproduction" xlink:href="<http://some.uri>http://some.uri"/>

but what I'm getting in my real work is

<accessCondition xmlns:xlink="<http://www.w3.org/1999/xlink>http://www.w3.org/1999/xlink"; type="use and reproduction" xlink:href="<http://some.uri>http://some.uri"/>

And they are equivalent, provided that the XLink namespaces is declared in the ancestry.


Thanks in advance for any light you can shed on this.

If you want the xlink:href= attribute absent in the given element, then you have to attach it to one of the elements in the ancestry. Most folks just go ahead and attach all desired namespace nodes to the document element so that they are in scope of all elements of the document and never need to be redeclared.


I hope this helps.

. . . . . . Ken


-- Contact info, blog, articles, etc. http://www.CraneSoftwrights.com/s/ | Check our site for free XML, XSLT, XSL-FO and UBL developer resources | Streaming hands-on XSLT/XPath 2 training class @ US$45 (5 hours free) |

Current Thread