...">

How to get namespace prefix as defined in stylesheet, not from XML input

I have this XML input:

<x:html xmlns:x="http://www.w3.org/1999/xhtml"/> 

and I use the following XSLT:

 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:y="http://www.w3.org/1999/xhtml" version="1.0"> <xsl:output method="text" indent="yes"/> <xsl:template match="*"> <xsl:value-of select="name()"/> </xsl:template> </xsl:stylesheet> 

The output I get (root element with the prefix x , as defined in the input XML)

 x:html 

Expected Result (root element with the prefix y , as defined in XSLT):

 y:html 
0
xslt xml-namespaces
Feb 16 '14 at 12:51 on
source share
1 answer

You can look at the axis axis namespace of the root element of your XSLT code, for example.

 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:y="http://www.w3.org/1999/xhtml" version="1.0"> <xsl:output method="text" indent="yes"/> <xsl:variable name="xslt-root" select="document('')/*"/> <xsl:template match="*"> <xsl:value-of select="concat(local-name($xslt-root/namespace::*[. = namespace-uri(current())]), ':', local-name())"/> </xsl:template> </xsl:stylesheet> 
+3
Feb 16 '14 at 13:11
source share



All Articles