This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: XML schema general convert with XSLT (namespaces..)
- To: ronald heller <ronald at salience dot nl>
- Subject: Re: [xsl] XML schema general convert with XSLT (namespaces..)
- From: Jeni Tennison <jeni at jenitennison dot com>
- Date: Fri, 21 Sep 2001 09:55:56 +0100
- CC: XSL-List at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <5.0.2.1.2.20010921092756.02768080@pop5.inter.nl.net>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Ronald,
> I have to know somehow in which namespace it is written, somehow. Is
> there anyway of telling which namespace is used? Sure I can give the
> used namespace as a paramter etc., but that really doesn't feel
> right.
If I understand correctly, you have a QName in an type attribute's
value (e.g. 'xs:string') and want to know the namespace URI that the
prefix 'xs' is associated with. You can do that by looking at the
namespace nodes on the attribute's parent element:
../namespace::*
You want to find the one whose name is the same as the prefix of the
QName:
../namespace::*[name() = substring-before(current(), ':')]
The value of that namespace node is the namespace URI. So you could
test whether a QName resolved to
{http://www.w3.org/2001/XMLSchema}string using:
(../namespace::*[name() = substring-before(current(), ':')] =
'http://www.w3.org/2001/XMLSchema') and
((contains(., ':') and substring-after(., ':') = 'string') or
. = 'string')
If you were doing lots of these tests in one place, I'd suggest using
variables to hold the pertinent information, i.e.:
<xsl:variable name="namespaceURI"
select="../namespace::*[name() =
substring-before(current(), ':')]" />
<xsl:variable name="localName">
<xsl:choose>
<xsl:when test="contains(., ':')">
<xsl:value-of select="substring-after(., ':')" />
</xsl:when>
<xsl:otherwise><xsl:value-of select="." /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$namespaceURI =
'http://www.w3.org/2001/XMLSchema' and
$localName = 'string'">
<xsl:text>Text</xsl:text>
</xsl:when>
...
<xsl:otherwise>
<xsl:text>UNKNOWN TYPE </xsl:text>
<xsl:value-of select="concat('{', $namespaceURI, '}')" />
<xsl:value-of select="$localName" />
</xsl:otherwise>
</xsl:choose>
If you were doing lots of the tests all over the place, I'd agree with
Mike that an extension function would be handy. For example, MSXML 4.0
offers msxsl:namespace-uri() and msxsl:local-name(), so if you were
using MSXML 4.0 you could do:
<xsl:choose>
<xsl:when test="msxsl:namespace-uri(.) =
'http://www.w3.org/2001/XMLSchema' and
msxsl:local-name(.) = 'string'">
<xsl:text>Text</xsl:text>
</xsl:when>
...
<xsl:otherwise>
<xsl:text>UNKNOWN TYPE </xsl:text>
<xsl:value-of select="concat('{', msxsl:namespace-uri(.), '}')" />
<xsl:value-of select="msxsl:local-name(.)" />
</xsl:otherwise>
</xsl:choose>
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list