[xsl] Accessing the input document's @xmlns

Subject: [xsl] Accessing the input document's @xmlns
From: Tim rdf <timrdf@xxxxxxxxx>
Date: Fri, 14 Dec 2012 10:14:17 -0500
Hello, xsl,

I'm working on an implementation for W3C's PROV recommendation [1],
and I ran into a roadblock that I hope this list can help me with.

If I have the following input document (shortened from [2], available at [3]):

=========================
<prov:document
    xmlns:prov="http://www.w3.org/ns/prov#";
    xmlns:ex="http://example.com/ns/ex#";>

  <prov:wasInvalidatedBy>
    <prov:entity prov:ref="ex:The-Painter"/>
    <prov:activity prov:ref="ex:crash"/>
    <prov:time>1998-09-03T01:31:00</prov:time>
    <ex:circumstances>plane accident</ex:circumstances>
  </prov:wasInvalidatedBy>

</prov:document>
=========================

I'm trying to access the value "http://example.com/ns/ex#"; given the
value "ex", without the transform knowing a priori.
To illustrate what I need, I have the following XSL, which needs a new
@select on the variable named "magic".

=========================
<xsl:transform
   version="2.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   xmlns:prov="http://www.w3.org/ns/prov#";>
<xsl:output method="text"/>

<xsl:key name="prefix" match="//prov:prefix" use="@prov:id"/>

<xsl:template match="/">

   <xsl:variable name="prefix"
select="substring-before(//prov:entity/@prov:ref,':')"/>

   <xsl:variable name="magic"
select="concat('magic(',$prefix,')=http://example.com/ns/ex#')"/>

   <!-- Cannot access /prov:document/@xmlns:ex using a
variable-constructed XPath.
    xsl:variable name="magic1" select="concat(prov:document/xmlns:',$prefix,')"/
   -->

   <!-- These two work, but require an addition of a <prov:prefix> element -->
   <xsl:variable name="magic2" select="//prov:prefix[@prov:id=$prefix]"/>
   <xsl:variable name="magic3" select="key('prefix',$prefix)"/>

   <xsl:value-of select="concat('The full URI of your painting is ',
                                $magic3,
                                substring-after(//prov:entity/@prov:ref,':'))"/>
</xsl:template>

</xsl:transform>
=========================



Some homework that I've done hasn't led me to a solution:

1)
http://www.dpawson.co.uk/xsl/sect2/nono.html#d1875e1050
suggests that one can't _write_ an @xmlns.
Which leads me to believe that one can't _read_ one, either.
I think the problem is that I don't ever have an element in the "ex"
namespace...

2)
http://www.dpawson.co.uk/xsl/sect2/nono.html#d1875e1290
might cover my issue by saying it's "never available", but could
someone confirm that?
I think this is the case.

3)
http://www.dpawson.co.uk/xsl/sect2/nono.html#d1875e40
seems to confirm that I can't construct the xpath to access the
/prov:document's attribute from a variable
<xsl:value-of select="concat(prov:document/xmlns:',$prefix,')"/>


Given this, I'm inclined to suggest to the PROV-WG that they include
something like:
  <prov:prefix prov:id="ex">http://example.com/ns/ex#</prov:prefix>

Thanks for your time and consideration. Am I missing any other alternative?

Regards,
Tim Lebo


[1] http://www.w3.org/TR/prov-overview/
[2] http://www.w3.org/TR/prov-xml/#term-Invalidation
[3] http://dvcs.w3.org/hg/prov/file/tip/examples/eg-43-xmlns-not-accessible/xml

Current Thread