This has nothing to do with using an XML schema. The problem is that you are specifying a default namespace .
Using XPath expressions for node names in the default namespace is XPath's biggest query.
Please find the xpath and xslt tags for the "default namespace" and you will find many good answers.
The solution for XSLT is to declare a namespace with some prefix (for example, "x") and namespace-uri, which matches the default namespace namespace in the XML document. Then, in any XPath expression, use x:name instead of name .
Thus, your XSLT code becomes :
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="http://localhost" exclude-result-prefixes="x" > <xsl:template match="/"> <ul> <xsl:for-each select="x:root/x:element"> <li> <xsl:value-of select="."/> </li> </xsl:for-each> </ul> </xsl:template> </xsl:stylesheet>
and when applied to the provided XML document using an element without comment <root> :
<root xmlns="http://localhost" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://localhost example.xsd"> <element>Element 1</element> <element>Element 2</element> <element>Element 3</element> </root>
required, the correct result is obtained :
<ul> <li>Element 1</li> <li>Element 2</li> <li>Element 3</li> </ul>
source share