Re: [xsl] Working with QNames in values

Subject: Re: [xsl] Working with QNames in values
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Sat, 3 Mar 2001 08:42:14 +0000
Hi Simon,

> I'm working with WSDL, which uses QNames in attribute values, but i'm
> having a hard time resolving the namespace-uri's from these, e.g.
>
> <foo xmlns:xsd="http://...";>
> <bar type="xsd:string" />
> </foo>
>
> In my XSLT (or more correctly, my schematron based schema), i want to
> be able to resolve the namespace uri of the xsd:string QName. I was
> hoping that the namspace-uri function would do it, but that returns
> the namespace uri of the attribute, not the value.

Hey, a use for namespace nodes!  I knew there had to be some point to
them :)

So, you get the type that you're after with:

  foo/bar/@type

Now, the part before the colon within that type is the prefix that's
being used in the source document for some namespace.  So get that
prefix:

  <xsl:variable name="prefix"
                select="substring-before(foo/bar/@type, ':')" />

Now, to find out what namespace URI that prefix is associated with,
you need to find the namespace node on the element that the value
comes from which has the same name as that prefix.  So look at
foo/bar, and find its namespace nodes:

  foo/bar/namespace::*

and then filter that to find the namespace node that is named after
that prefix (I'm using local-name() here because the MSXML
implementation wrongly gives the full name() as 'xmlns:xsd'):

  foo/bar/namespace::*[local-name() = $prefix]

The string value of that namespace is the namespace URI for the
namespace, so getting the string value of the above will get you the
namespace URI you're after.

[Note: The namespace-uri() function gets you the namespace of the
element/attribute - in the example above it resolves to the empty
string because they're not in a namespace.]

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread