xsl-list
[Top] [All Lists]

Re: Converting attribute value qnames to URIs

2004-03-25 10:50:42

                <!-- URI that the prefix maps to: first ancestor with a
                          namespace node whose name() = the namespace prefix. 
-->
                <xsl:variable name="nsNode">
                  <xsl:value-of select=
           "ancestor-or-self::*[1]/namespace::*[name() = $nsprefix]"/>

The quoted code doesn't do what the comment says, it doesn't select the
first ancestor with a namespace node, it selects the first ancestor or
self (always) and then selects the namespace node of that.
This is actually OK at present as namespace prefixes can't be
undeclared so if any ancestor has such a node, the nearest ancestor will
have such a node. (This becomes false in xml namespaces 1.1)
as the current node is an attribute the -self bit isn't needed either
as the attribute will never match * so the above is
parent::*/namespace::*[name() = $nsprefix]


        <xsl:variable name="nsNode">
                  <xsl:value-of select=
           "ancestor-or-self::*[1]/namespace::*[name() = $nsprefix]"/>
                </xsl:variable>

this makes a result tree fragment, if instead you went

        <xsl:variable name="nsNode"select=
           "ancestor-or-self::*[1]/namespace::*[name() = $nsprefix]"/>
 
(or parent:*) then it would probably be a bit more efficient and you
could simplify your test

  <xsl:when test="$nsNode=''">

to

  <xsl:when test="$nsNode">

as you could just directly test whether the node exists rather than test
if its string value is empty.




 <!-- Add attribute to result tree, substituting URI for prefix. -->
         <xsl:attribute name="{name()}">
                <xsl:value-of select="$nsURI"/>
                <xsl:value-of select="substring-after(.,':')"/>
         </xsl:attribute>


don't you want to put in some separator between teh uri and local name,
so the transformation is reversible? eg James clark's
{uri}name
notation?


David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


<Prev in Thread] Current Thread [Next in Thread>