Subject: Re: [xsl] XML schema general convert with XSLT (namespaces..) From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Fri, 21 Sep 2001 09:55:56 +0100 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] XML schema general conver, Michael Kay | Thread | [xsl] Counting Footnotes, Nicholas Waltham |
RE: [xsl] XML schema general conver, Michael Kay | Date | [xsl] Counting Footnotes, Nicholas Waltham |
Month |