Forum Moderators: open

Message Too Old, No Replies

exclude-result-prefixes Whack-A-Mole

Nail it in one element, and it pops up in another

         

cmarshall

12:08 pm on Mar 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Moving right along, I've gotten all the XSLT stuff down, so I have valid XML, Valid Schema and operational XSLT. However, the issue now is that XSLT insists on putting namespaces into the HTML. This breaks HTML validation, so I want to suppress the namespace.

Here's what an HTML transform looks Like:

<!DOCTYPE html PUBLIC "-//W3c//DTD HTML 4.01//EN" "http://www.w3c.org/tr/html4/strict.dtd">
<html xmlns:wt="http://www.example.com">
<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>

The red part is the part in question.

By poking around, I found out about

exclude-result-prefixes
. I add that to the
<html>
element in the XSLT file, thusly:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wt="http://www.example.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 xsl:exclude-result-prefixes="wt">
<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>

However, we now have whacked one mole, only to have another pop up, thusly:

<!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 xmlns:wt="http://www.example.com">
<ul>
<li>Test</li>
</ul>
</li>
</ul>
</body>
</html>

This will continue, so there must be a global way to do it. I'll figure it out soon, I'm sure, but I love the sound of crickets chirping, so I'll keep on asking here.

Why do I keep posting here, when I have yet to receive a single answer, and I keep solving my own problems in minutes or hours?

Because these issues are, from what I have seen, pretty typical of what people learning XML/XSLT go through, and I think it would be nice to leave a record of answers written in something other than the typical XML cuneiform script.

I'm absolutely appalled at the incredibly obtuse verbiage out there for XML. There is a TON of information and dozens of tools, but most of it is for people who have already gone past this point. The book I'm using as a text has holes through which you could drive a Mack truck.

I have had a great deal of difficulty deciphering some of the very muddy explanations out there into plain English that I can use to address these issues. In fact, most of the help I've received has been by reading threads posted by people as frustrated by the obfuscation as am I.

[edited by: encyclo at 5:11 pm (utc) on Mar. 26, 2007]
[edit reason] examplified [/edit]

cmarshall

1:14 pm on Mar 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Okay, that problem is solved.

It requires that the

exclude-result-prefixes
attribute be placed in the stylesheet declaration, but without the xsl namespace prefix:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wt="http://www.example.com" exclude-result-prefixes="wt">
<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>

[edited by: encyclo at 5:11 pm (utc) on Mar. 26, 2007]