Re: [xsl] Help namespacing an attribute

Subject: Re: [xsl] Help namespacing an attribute
From: "Bridger Dyson-Smith bdysonsmith@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 20 Sep 2017 17:31:52 -0000
Hi Ken -

Thanks for the response!

On Wed, Sep 20, 2017 at 1:11 PM, G. Ken Holman g.ken.holman@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> 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.
>
That's a good bit of clarification I'll remember for the future!

>

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.
>
> So that's exactly what I've done in both examples; e.g.
<new-record xmlns="http://def.net/ns"; xmlns:xlink="http://www.w3.
org/1999/xlink"> and
<mods xmlns="http://www.loc.gov/mods/v3"; version="3.5" xmlns:xlink="
http://www.w3.org/1999/xlink";>

I was thinking that maybe I hadn't declared a namespace correctly, but
based on your comments it seems like I have. Now I'm confused about why the
processor decides to serialize the namespace declaration to the child
element instead at the document element. Or maybe that's not what's
happening.

In any event, as you say, the result is still valid. The concern arises
from the fact that the MODS here is being used as an interchange format and
the main consumer converts everything to JSON and then does processing on
their end. I'm not sure what, if anything, will happen as a result of the
serialization change on my end.

I hope this helps.
>
It is helpful and much appreciated.

>
> . . . . . . Ken
>
> Thanks again!
Bridger


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