Solved

XSL adding xmlns="" automatically

Posted on 2007-11-20
9
2,572 Views
Last Modified: 2013-11-18
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="xhtml">
  <xsl:output encoding="UTF-8" method="html" indent="yes" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" doctype-public="-//W3C//DTD 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.
0
Comment
Question by:x2cmsac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 250 total points
ID: 20324448
Your default xmlns should be that of the w3c. Try this:

<?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" exclude-result-prefixes="" >

      <xsl:output
method="html"
version="4.0"
encoding="iso-8859-1"
indent='yes'
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd" />
0
 

Author Comment

by:x2cmsac
ID: 20324553
Thats fixed the xmlns issue but now its stripping all the closing tags, its not proper XHTML ?

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?
0
 
LVL 82

Expert Comment

by:hielo
ID: 20324587
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:x2cmsac
ID: 20324637
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 ?
0
 
LVL 82

Expert Comment

by:hielo
ID: 20324668
> 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="announcements dc" >

      <xsl:output method="html" version="4.0" encoding="iso-8859-1" indent='yes' doctype-public="-//W3C//DTD 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>
0
 

Author Comment

by:x2cmsac
ID: 20324712
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.
0
 

Author Comment

by:x2cmsac
ID: 20324731
And all i changed was a typo in the title and closing xsl:template element.
0
 
LVL 82

Expert Comment

by:hielo
ID: 20325228
Weird. I have used that setup on MSXML parser and also on whatever it is that comes in LINUX/PHP platforms.
0
 
LVL 60

Assisted Solution

by:Geert Bormans
Geert Bormans earned 250 total points
ID: 20326168
> I've always used it to create XHTML with strict doctype and have never seen that problem before

that is strange, you must not have been paying attention.

If the output mehod is set to html, the xslt processor must serialise as html
and html is NOT wellformed because it doesn't allow (in the strict sense)
end tags for img, meta and link (and likely a couple of others)
since a meta tag is added automatically during serialisation, the one with the encoding,
there is little chance that the resulting HTML will be wellformed XHTML
If you want XHTML, you need the output method to be XML

About the <foo></foo> vs. <foo/>
> <meta name="keywords" content="............."></meta>
> Which should just be -
> <meta name="keywords" content="............."/>
> Is there anyway to change this in XSLT  / workaround ?

In XML (or XHTML) terms they are equal... so it really doesn't matter
the serialiser of the processor picks how he wants to deal with this... and you can't control it
If you really want it differently, you need a Ruby (or Python, ...) postprocess to fix it with a regular expression
I strongly recommend you to leave it as it is, XML parsers don't bother and they should not
Note that in hielo's counter examples there never is an end tag for meta... since he serialises as html

And to answer your original question
the xmlns="" appears because you are constructing the div element in a namespace other than the default namespace of your document
it would help if you added this doument in the correct namespace
<xsl:element name="div" namespace="http://www.w3.org/1999/xhtml">
....
</xsl:element>
I need to see the full XML and XSLT to make sure I got this example right

cheers

Geert

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question