I am having difficulties referencing all 3.
I have already written my XML,XSD and XSL but it doesn’t seem to work with the referencing.
Here is a simple example using the same referencing.
XSD:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="email">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="email.xsl"?>
<email
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com email.xsd">
<to>John</to>
</email>
XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="email">
<h2>To</h2>
<td><xsl:value-of select="John"/></td>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The XSLT does not work because your
emailelement has a namespace, and to match an element with a namespace using an XPath you always have to explicitely declare a prefix and use it.You need to write the XSL like this:
I am not sure what you are expecting from the XSD: it seems correct, but it won’t affect in any way the application of the XSLT.
emailis the root element in your XML, so you can have only oneemailelement per XML file – probably you should have a different root element above it.Note also that you are generating dubious HTML: a
<td>that is not inside a table.