एक और:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*">
<xsl:param name="pNamespaces" select="'
'"/>
<xsl:variable name="vNamespaces">
<xsl:variable name="vMyNamespaces">
<xsl:value-of select="$pNamespaces"/>
<xsl:for-each select="namespace::*
[not(contains(
$pNamespaces,
concat('
',.,'
')))]">
<xsl:value-of select="concat(.,'
')"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="vChildsNamespaces">
<xsl:apply-templates select="*[1]">
<xsl:with-param name="pNamespaces"
select="$vMyNamespaces"/>
</xsl:apply-templates>
</xsl:variable>
<xsl:value-of select="concat(substring($vMyNamespaces,
1 div not(*)),
substring($vChildsNamespaces,
1 div boolean(*)))"/>
</xsl:variable>
<xsl:variable name="vFollowNamespaces">
<xsl:apply-templates select="following-sibling::*[1]">
<xsl:with-param name="pNamespaces" select="$vNamespaces"/>
</xsl:apply-templates>
</xsl:variable>
<xsl:value-of
select="concat(substring($vNamespaces,
1 div not(following-sibling::*)),
substring($vFollowNamespaces,
1 div boolean(following-sibling::*)))"/>
</xsl:template>
</xsl:stylesheet>
आउटपुट (Dimitre के इनपुट नमूना के साथ):
http://www.w3.org/XML/1998/namespace
mynamespace
mynamespace2
mynamespace3
संपादित: इसके अलावा इस XPath अभिव्यक्ति:
//*/namespace::*[not(. = ../../namespace::*|preceding::*/namespace::*)]
सबूत के रूप में, इस स्टाइलशीट:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each select="//*/namespace::*
[not(. = ../../namespace::*|
preceding::*/namespace::*)]">
<xsl:value-of select="concat(.,'
')"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
आउटपुट:
http://www.w3.org/XML/1998/namespace
mynamespace
mynamespace2
mynamespace3
संपादित करें 4: दो पास परिवर्तन के रूप में ही कुशल।
यह स्टाइलशीट:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:key name="kElemByNSURI"
match="*[namespace::*[not(. = ../../namespace::*)]]"
use="namespace::*[not(. = ../../namespace::*)]"/>
<xsl:template match="/">
<xsl:for-each select=
"//namespace::*[not(. = ../../namespace::*)]
[count(..|key('kElemByNSURI',.)[1])=1]">
<xsl:value-of select="concat(.,'
')"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
आउटपुट:
http://www.w3.org/XML/1998/namespace
mynamespace
mynamespace2
mynamespace3
संपादित 5: आप namespace
कुल्हाड़ी कार्यान्वयन (TransforMiix की तरह) के बिना एक XSLT प्रोसेसर के साथ काम कर रहे हैं, तो आप केवल निकाल सकते हैं नामस्थान वास्तव में इस स्टाइलशीट के साथ प्रयोग किया जाता है:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:key name="kElemByNSURI" match="*|@*" use="namespace-uri()"/>
<xsl:template match="/">
<xsl:for-each select=
"(//*|//@*)[namespace-uri()!='']
[count(.|key('kElemByNSURI',namespace-uri())[1])=1]">
<xsl:value-of select="concat(namespace-uri(),'
')"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
ट्रांसफोर्मिक्स आउटपुट:
mynamespace2
अच्छा प्रश्न (+1)। एक संक्षिप्त और कुशल समाधान के लिए मेरा जवाब देखें। :) –
मैंने अभी अपने जवाब में एक एक्सएसएलटी 2.0 समाधान जोड़ा - बस पूर्णता के लिए। –