x2cmsac
asked on
XSL adding xmlns="" automatically
I am a relative notice to XSL - I am using XSL to produce XHTML pages.
I have a problem where the XSL is adding xmlns="" to HTML nodes in my XSL.
I have two files I will show you the head of each because i think this is effecting whats happening
page.xsl -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml" exclude-result-prefixes="x html">
<xsl:output encoding="UTF-8" method="html" indent="yes" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" doctype-public="-//W3C//DT D XHTML 1.0 Strict//EN"/>
<xsl:include href="common.xsl"/>
And page.xsl uses a file called common.xsl -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="no" method="xml" omit-xml-declaration="yes" />
All the HTML in page.xsl seems fine but items in common.xsl e.g. -
<xsl:template name="toc">
<div id="toc"></div>
</xsl:template>
Are produced in HTML as -
<div id="toc" xmlns=""></div>
I want to stop the XSL adding xmlns="" to these elements, how do i do this?
Im using ASP.NET so its Microsoft XSL processor - not sure if this makes a difference.
I have a problem where the XSL is adding xmlns="" to HTML nodes in my XSL.
I have two files I will show you the head of each because i think this is effecting whats happening
page.xsl -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml" exclude-result-prefixes="x
<xsl:output encoding="UTF-8" method="html" indent="yes" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" doctype-public="-//W3C//DT
<xsl:include href="common.xsl"/>
And page.xsl uses a file called common.xsl -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="no" method="xml" omit-xml-declaration="yes"
All the HTML in page.xsl seems fine but items in common.xsl e.g. -
<xsl:template name="toc">
<div id="toc"></div>
</xsl:template>
Are produced in HTML as -
<div id="toc" xmlns=""></div>
I want to stop the XSL adding xmlns="" to these elements, how do i do this?
Im using ASP.NET so its Microsoft XSL processor - not sure if this makes a difference.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I've always used it to create XHTML with strict doctype and have never seen that problem before. My stand-alone tags remamin properly closed. There must be something else going on. Post your XSL.
ASKER
Thanks for the help.
Im assuming this has todo with the XSLT processor. I changed method="html" to method="xml" and it now closes the stand alone tags properly.
I might need to raise this as a seperate ticket but now i have another problem...
<xsl:template name="metakeyword">
<xsl:param name="pagekeywords"/>
<xsl:element name="meta">
<xsl:attribute name="name">keywords</xsl: attribute>
<xsl:attribute name="content">
<xsl:value-of select="$pagekeywords"/>
</xsl:attribute>
</xsl:element>
</xsl:template>
is producing as -
<meta name="keywords" content="............."></ meta>
Which should just be -
<meta name="keywords" content="............."/>
Is there anyway to change this in XSLT / workaround ?
Im assuming this has todo with the XSLT processor. I changed method="html" to method="xml" and it now closes the stand alone tags properly.
I might need to raise this as a seperate ticket but now i have another problem...
<xsl:template name="metakeyword">
<xsl:param name="pagekeywords"/>
<xsl:element name="meta">
<xsl:attribute name="name">keywords</xsl:
<xsl:attribute name="content">
<xsl:value-of select="$pagekeywords"/>
</xsl:attribute>
</xsl:element>
</xsl:template>
is producing as -
<meta name="keywords" content="............."></
Which should just be -
<meta name="keywords" content="............."/>
Is there anyway to change this in XSLT / workaround ?
> Is there anyway to change this in XSLT / workaround ?
Not that I am aware off. The reason being that your output is XML and that is perfectly valid XML syntax. It is the result of using "XML" vs. "HTML".
This is how I set up my xsl, and am still able to get the <link ... />:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xmlns:announcements="http://www.adagreatlakes.org" xmlns:dc="http://purl.org/dc/elements/1.1/" exclude-result-prefixes="a nnouncemen ts dc" >
<xsl:output method="html" version="4.0" encoding="iso-8859-1" indent='yes' doctype-public="-//W3C//DT D XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd" />
<!-- "main" -->
<xsl:template match="/" >
<html xml:lang="en-us" lang="en-us">
<head>
<title>Test></title>
<link href="" type="text/css" />
</head>
<body>
<h1>Hi</h1>
</body>
</html>
</xsl:/template>
Not that I am aware off. The reason being that your output is XML and that is perfectly valid XML syntax. It is the result of using "XML" vs. "HTML".
This is how I set up my xsl, and am still able to get the <link ... />:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xmlns:announcements="http://www.adagreatlakes.org" xmlns:dc="http://purl.org/dc/elements/1.1/" exclude-result-prefixes="a
<xsl:output method="html" version="4.0" encoding="iso-8859-1" indent='yes' doctype-public="-//W3C//DT
<!-- "main" -->
<xsl:template match="/" >
<html xml:lang="en-us" lang="en-us">
<head>
<title>Test></title>
<link href="" type="text/css" />
</head>
<body>
<h1>Hi</h1>
</body>
</html>
</xsl:/template>
ASKER
That code for me produces -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd">
<html xml:lang="en-us" lang="en-us" xmlns="http://www.w3.org/1999/xhtml">
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-16">
<title>Test</title>
<link href="" type="text/css">
</head>
<body>
<h1>Test</h1>
</body>
</html>
With the link tag not closed properly, ive no idea whats causing it.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd">
<html xml:lang="en-us" lang="en-us" xmlns="http://www.w3.org/1999/xhtml">
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-16">
<title>Test</title>
<link href="" type="text/css">
</head>
<body>
<h1>Test</h1>
</body>
</html>
With the link tag not closed properly, ive no idea whats causing it.
ASKER
And all i changed was a typo in the title and closing xsl:template element.
Weird. I have used that setup on MSXML parser and also on whatever it is that comes in LINUX/PHP platforms.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
e.g.
<link rel="stylesheet" href="/css/style.css" type="text/css"/>
is being transformed to -
<link rel="stylesheet" href="/css/style.css" type="text/css">
Its removing all the closing elements?
How do i make it conform to proper XHTML?