Re: [xsl] Qualified Attrib Value

Subject: Re: [xsl] Qualified Attrib Value
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 20 Aug 2002 12:37:30 +0100
Hi Steven,

> How do I get the value of the "test" attrib (contains a value
> qualified in myprefix associated namespace) within this fragment
> without the prefix? (not using string manipulation, but proper
> Xpath).
>
> <el test="myprefix:val" />

XSLT 1.0 doesn't support schemas, so an XSLT 1.0 processor doesn't
know that the test attribute contains a qualified name, from which it
should be able to extract a local part and a namespace URI. As far as
the XSLT 1.0 processor is concerned, the test attribute contains a
string. So if you want to get information from that string then you
*have* to use string manipulation:

  substring-after(@test, ':')

When XPath 2.0 comes around, if you work with a processor that
supports W3C XML Schema and you have a schema that says that the test
attribute is of type xs:QName then the test attribute's "typed value"
will be the qualified name. You can get the typed value of a node with
the data() function. You can then extract the local part of the QName
with the get-local-name-from-QName() function, so use:

  get-local-name-from-QName(data(@test))

[Each time I think about using these get-property-from-dataType()
 functions I want to scream.]

You'll still be able to use the former method in XPath 2.0, and that
gives you the benefit of not relying on someone using a W3C XML
Schema-aware XSLT processor (which I imagine will be rare beasts) nor
on the schema being available when you do the transformation (a risky
assumption in a networked environment), but the latter will deal
comfortably with the situation where the qualified name in the test
attribute doesn't have a prefix, whereas the string manipulation
method returns an empty string in that case.
 
Cheers,

Jeni

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


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


Current Thread