Obtaining an Xml Namespace from a Prefix in Xslt 1.0 July, 2009
I have been struggling for a while now to get a namespace from a prefix with xslt 1.0. Here is a sample fragment from a wsdl file:
<xs:complexType> <xs:sequence> <xs:element ... xmlns:q2="urn:Some/Namespace" type="q2:SomeDataContract" /> xs:sequence> xs:complexType>
So I want to obtain the namespace associated with the "q2" prefix (Which is dynamically generated) so I'm going to have to extract it from the type attribute and somehow get the namespace by the prefix. Well here is how you do it:
<xsl:variable name="namespacePrefix" select="substring-before(@type, ':')"/> <xsl:value-of select="namespace::*[local-name(.)=$namespacePrefix]" />
Hopefully this saves you some time.