I'm propably doing something stupid here, I bet there is an easier way... I need to access namespace of a node. Elements in my xml looks for example like this:
<somenamespace:element name="SomeName">
Then in my xslt I access this elements with:
<xsl:template match="*[local-name()='element']">
<xsl:variable name="nodename">
<xsl:value-of select="local-name(current())"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains($nodename,':')">
Well, of course it doesn't work, because there is no "somenamespace" namespace even in template match...
Can anyone guide me, what am I looking for?
The namespace http://www.w3.org/1999/XSL/Transform is referred to as "the XSLT namespace". The prefix xsl is conventionally used to refer to this namespace (and is so used both within this document and within the XSLT specification), but it has no special status: any prefix may be used.
Provided that you're using XSLT 2.0, all you have to do is add the xpath-default-namespace attribute on the document element of each stylesheet: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xpath-default-namespace="http://example.com"> ...
XSLT format-number is defined to convert a number into a string value using the second argument's pattern. This is the type conversion formatting output. We use a different notation for numbers like comma for decimal formats and some points for thousands representation. To use all these, XSL uses format-number.
XSLT current() Function The current() function returns a node-set that contains only the current node. Usually the current node and the context node are the same.
It looks to me as if you want to test whether the node is in a non-null namespace. The correct way to do that is
namespace-uri() != ''
You shouldn't be looking at whether the lexical name has a prefix or contains a colon, because if the node is in a namespace then it can be written either with a prefix or without, and the two forms are equivalent.
But I'm guessing as to what your real, underlying, requirement is.
You are looking for name
function, e..g.:
<xsl:value-of select="name()"/>
returns somenamespace:element
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With