[xsl] Setting variable to namespace prefix

Subject: [xsl] Setting variable to namespace prefix
From: <sthomas2@xxxxxxx>
Date: Tue, 30 Jan 2007 16:37:57 -0500
Apologies in advance for what's certainly a rookie question, but I guess
I've got to start somewhere. I'm trying to assign an xsl:variable to the
value of the namespace prefix for current context (using <oXygen/> with
Saxon6.5.5)

For example, I have the XML fragment:

<xsd:schema xmlns:common="http://[url]";
            xmlns:xsd="http://www.w3.org/2001/XMLSchema";
            targetNamespace="http://[url]";
            elementFormDefault="qualified">
  <xsd:complexType name="name"/>
</xsd:schema>

Where [url] is the same value in both cases.

I would expect the following to set the ns-prefix variable to "common"

<xsl:variable name="ns-prefix">
  <xsl:for-each select="namespace::node()">
    <xsl:if test="(.)=(../../@targetNamespage)">
      <xsl:value-of select="name(.)"/>
    </xsl:if>
  </xsl:for-each>
</xsl:variable>

I can step through the transformation in <oXygen/> and verify that the
test is true and name(.) contains the value "common", but (probably for
some really dumb reason that I'm just missing) the variable isn't being
set.

Help is appreciated.

TIA, Stephen

P.S. Extra apologies if the answer to this question is in the FAQ or the
archives. I suspect it is, but I'm just not recognizing it.

Current Thread