XSL for <schema xmlns="http://www.w3.org/2001/XMLSchema">
What will be the equivalent XSL style sheet f开发者_如何学Goor <schema xmlns="http://www.w3.org/2001/XMLSchema">
Update: The OP provided his code.
Use:
<xsl:for-each select="x:schema/x:element">
Instead of:
<xsl:for-each select="schema/element">
Search/read about "default namespace in XPath". This is a F A Q
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:x="http://www.w3.org/2001/XMLSchema">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:value-of select="/x:schema/x:a/x:b/x:c"/>
</xsl:template>
</xsl:stylesheet>
when applied on this XML document:
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<a>
<b>
<c>d</c>
</b>
</a>
</schema>
produces the wanted result:
d
Explanation: Any unprefixed name in an XPath expression is always considered to be in "no namespace". If the XML document has a default namespace, then any element of this document is in the default namespace (not in "no namespace). Therefore, for such a document unprefixed names don't select any node -- because not a single node in this document is in "no namespace".
精彩评论