Nodonutsforyou
Nodonutsforyou

Reputation: 458

Select name of alias of xmlns atribute by xpath

Say I have xml with xmlns:alias attribute:

I need to select allias name from desired namespace?

<exmpletag
    xmlns:x="http://www.someurl.url"
>
<sometags/>
<exmpletag>

How do I select x from exmpletag tag?

Upvotes: 0

Views: 697

Answers (1)

JLRishe
JLRishe

Reputation: 101690

Supposing the current context (.) is the exmpletag element, you should be able to do so like this:

local-name(namespace::*[. = 'http://www.someurl.url'])


Example usage:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text" indent="yes"/>

    <xsl:template match="exmpletag">
      <xsl:value-of select="local-name(namespace::*[. = 'http://www.someurl.url'])"/>
    </xsl:template>
</xsl:stylesheet>

Output when run on your sample XML (after fixing it to be well-formed):

x

I would provide an xsltcake example, but the site appears to be down right now.

Upvotes: 1

Related Questions