Forum Moderators: open
However, it is now time to XSLT the XML, and the XSLT is failing.
Basically, the
<xsl:template> elements are failing. This seems to be because of a default namespace in the XML file. If I remove that namespace, the XML works fine, but the schema validation fails (of course). I KNOW this simple problem can be solved. It's probably a real basic issue. I need to make sure that the
<xsl:template> picks up the elements. Here are very, very brief examples of what I mean. I'll explain inline:
First, I have the XML Output (wee_test.xml):
<?xml version="1.0" encoding="ISO-8859-1"?>
<weetest xmlns="http://www.weetest.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.weetest.com file:/Users/cmarshall/Desktop/XMLTest/wee_test/wee_test.xsd">
<elementwrapper id="1">
<data_name>Test</data_name>
</elementwrapper>
</weetest>
Note the red section. That's the culprit.
Next, we have the schema file (wee_test.xsd):
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.weetest.com"
elementFormDefault="qualified">
<xs:element name="weetest">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="elementwrapper">
<xs:complexType>
<xs:sequence>
<xs:element name="data_name" type="xs:string"/>
</xs:sequence>
which is the meeting ID. -->
<xs:attribute name="id" type="xs:integer" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The XML validates correctly against this schema (The schema-location in the XML header needs to be adjusted to wherever your schema file lives).
And finally, we have the star of the show, the XSL stylesheet (wee_test.xsl):
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.01"/>
<xsl:output doctype-system="http://www.w3c.org/tr/html4/strict.dtd"/>
<xsl:output doctype-public="-//W3c//DTD HTML 4.01//EN"/>
<xsl:template match="/">
<html>
<head>
<title>XML Test</title>
</head>
<body>
<ul><xsl:apply-templates/></ul>
</body>
</html>
</xsl:template>
<xsl:template match="weetest">
<li><ul><xsl:apply-templates/></ul></li>
</xsl:template>
<xsl:template match="data_name">
<li><xsl:apply-templates/></li>
</xsl:template>
</xsl:stylesheet>
This is expected to produce the following:
<!DOCTYPE html PUBLIC "-//W3c//DTD HTML 4.01//EN" "http://www.w3c.org/tr/html4/strict.dtd">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>XML Test</title>
</head>
<body>
<ul>
<li>
<ul>
<li>Test</li>
</ul>
</li>
</ul>
</body>
</html>
However, what it actually produces is:
<!DOCTYPE html PUBLIC "-//W3c//DTD HTML 4.01//EN" "http://www.w3c.org/tr/html4/strict.dtd">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>XML Test</title>
</head>
<body>
<ul>
Test
</ul>
</body>
</html>
This is because the
<xsl:template> elements are failing to match the XML data. This is apparently because they live in different namespaces. If I remove the default namespace (in red, in the XML file, above), the transform works, but, of course, validation fails.
Does ayone know which M I should RTFM? Any suggestions?
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wt="http://www.weetest.com">
<xsl:output method="html" version="4.01"/>
<xsl:output doctype-system="http://www.w3c.org/tr/html4/strict.dtd"/>
<xsl:output doctype-public="-//W3c//DTD HTML 4.01//EN"/>
<xsl:template match="/">
<html>
<head>
<title>XML Test</title>
</head>
<body>
<ul><xsl:apply-templates/></ul>
</body>
</html>
</xsl:template>
<xsl:template match="wt:weetest">
<li><ul><xsl:apply-templates/></ul></li>
</xsl:template>
<xsl:template match="wt::data_name">
<li><xsl:apply-templates/></li>
</xsl:template>
</xsl:stylesheet>