XMLNS issues with XSL transformation.
-
OK, I've got my source document, right? And it uses two different namespaces, my custom one and the XHTML one. The contents of it are a mix of XHTML and my own markup. So the header on that looks like this:
<Page xmlns="/PageWriter/TemplateSchema.xsd" xmlns:XHTML="http://www.w3.org/1999/xhtml">
Now, I've got my XSL stylesheet, right? And it's used to take the source document and transform it into pure XHTML. So I've figured out that I need to do this in my header, I think:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:MHC="/PageWriter/TemplateSchema.xsd"><xsl:output encoding="utf-8" indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" /> <xsl:template match="/"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
And thereafter all references in my
<xsl:...>
tags that refer to my own custom elements use the prefixMHC:
, like so:<title>MadHamster Creations - <xsl:value-of select="MHC:Page/MHC:Head/MHC:Title" /></title>
BUT! The problem is now that I have a few weird output issues. The first of all, and this one is really bad because it makes my documents not validate as XHTML, is that my
<html>
tag now looks like this:<html xml:lang="en-US" lang="en-US" xmlns:MHC="/PageWriter/TemplateSchema.xsd" xmlns="http://www.w3.org/1999/xhtml">
Not like this, which is how it's supposed to look but doesn't:
<html xml:lang="en-US" lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
The other weird thing occurs only when I call a template from inside my main template, like so:
<xsl:apply-templates select="MHC:Page/MHC:Body" />
The header for the other template is:
<xsl:template match="MHC:Page/MHC:Body" name="ProcessBody">
Inside the main template, everything works fine. But when I call this other template, all of my XHTML elements generated inside that template have this extra attribute in them. The attribute is
xmlns=""
, which is needless to say redundant, although it doesn't make the document invalid. Why? How can I stop it? Anyone who wants more in-depth information can get my source files and a .NET utility to transform them, by e-mailing me. -
OK, I've got my source document, right? And it uses two different namespaces, my custom one and the XHTML one. The contents of it are a mix of XHTML and my own markup. So the header on that looks like this:
<Page xmlns="/PageWriter/TemplateSchema.xsd" xmlns:XHTML="http://www.w3.org/1999/xhtml">
Now, I've got my XSL stylesheet, right? And it's used to take the source document and transform it into pure XHTML. So I've figured out that I need to do this in my header, I think:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:MHC="/PageWriter/TemplateSchema.xsd"><xsl:output encoding="utf-8" indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" /> <xsl:template match="/"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
And thereafter all references in my
<xsl:...>
tags that refer to my own custom elements use the prefixMHC:
, like so:<title>MadHamster Creations - <xsl:value-of select="MHC:Page/MHC:Head/MHC:Title" /></title>
BUT! The problem is now that I have a few weird output issues. The first of all, and this one is really bad because it makes my documents not validate as XHTML, is that my
<html>
tag now looks like this:<html xml:lang="en-US" lang="en-US" xmlns:MHC="/PageWriter/TemplateSchema.xsd" xmlns="http://www.w3.org/1999/xhtml">
Not like this, which is how it's supposed to look but doesn't:
<html xml:lang="en-US" lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
The other weird thing occurs only when I call a template from inside my main template, like so:
<xsl:apply-templates select="MHC:Page/MHC:Body" />
The header for the other template is:
<xsl:template match="MHC:Page/MHC:Body" name="ProcessBody">
Inside the main template, everything works fine. But when I call this other template, all of my XHTML elements generated inside that template have this extra attribute in them. The attribute is
xmlns=""
, which is needless to say redundant, although it doesn't make the document invalid. Why? How can I stop it? Anyone who wants more in-depth information can get my source files and a .NET utility to transform them, by e-mailing me.Heya, to get rid of the unnecessary XSL/XML info in your ouptut data then put the attribute 'exclude-result-prefixes' in the xsl:stylesheet node, like this: Just space-separate all the namespace prefixes you do not want in the result. I also set the 'omit-xml-declaration' to "yes" in the xsl:output element to get rid of the XML declaration. /WW
-
Heya, to get rid of the unnecessary XSL/XML info in your ouptut data then put the attribute 'exclude-result-prefixes' in the xsl:stylesheet node, like this: Just space-separate all the namespace prefixes you do not want in the result. I also set the 'omit-xml-declaration' to "yes" in the xsl:output element to get rid of the XML declaration. /WW
Thanks a ton for the response! I was beginning to think nobody knew... Anyways, the
exclude-result-prefixes
works great to get rid of the extraxmlns:MHC="..."
in my<html>
tag. I need to keep the XML declaration for valid XHTML however, but thanks for the help anyways. So, any ideas on the emptyxmlns=""
attribute that pops up in those elements? Rather weird... Thanks again, it's really reat to have someone who knows this stuff!-Domenic Denicola- [CPUA 0x1337] MadHamster Creations "I was born human. But this was an accident of fate - a condition merely of time and place. I believe it's something we have the power to change..."