Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 23rd, 2004, 10:33 AM
Authorized User
 
Join Date: Jun 2003
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Kabe
Default attribute xmlns added in included xsl

hi

using these settings:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="ISO-8859-1" version="4.0" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" media-type="text/html"/><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >

Problem:
- tags used in first xsl are ok.
- when importing xslfile into main file, an attribute xmlns="" is added to each html-tag

i'm using these headers in xsl-import files:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

how to avoid xsl imported files from adding xmlns="" after parsing ?

thx,
kabe.be
 
Old November 23rd, 2004, 10:43 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

xmlns="" is not an attribute it's a namespace declaration.
It's hard to say exaclty what's causing it without seeing the files but if you create an element in a default namespace, e.g.
Code:
<html xmlns="http://www.w3.org/1999/xhtml"/>
and then you create another element within that one without a namespace then you must undeclare the namespace with xmlns="". E.g.:
Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<xsl:element name="body"/>
</html>
body has no namespace declared so results must be like this:
Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<body xmlns=""/>
</html>
The fact that you have a dtd means namespace declarations maybe being enforced via that.



--

Joe (Microsoft MVP - XML)
 
Old November 23rd, 2004, 10:49 AM
Authorized User
 
Join Date: Jun 2003
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Kabe
Default

indeed, that's just the point that xmlns="" is added

(detail: i'm using msxml4.0)

it's the first time i'm facing this problem cause I want to create strict xhtml.

If you like, I can send u the (2) files
 
Old November 23rd, 2004, 11:05 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Can you show an small example of the xslt and the result you want versus the result you get?

--

Joe (Microsoft MVP - XML)
 
Old November 23rd, 2004, 11:16 AM
Authorized User
 
Join Date: Jun 2003
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Kabe
Default

Here the examples. As you'll see, the problem occurs only in the include on first level (2.), include on second level (3.) is again ok.

1. default.xsl: Master XSL
**************************
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:include href="includes/mainbox/main_default.xsl"/>

<xsl:output method="html" encoding="ISO-8859-1" version="4.0" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" media-type="text/html"/>
<xsl:template match="/">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl">
 <head>
<title></title>

<xsl:for-each select="//PROPERTIES/RECORDS[@label = 'css']/RECORD">
    <link rel="stylesheet" type="text/css" media="{type}" href="{$CssPath}{file}" />
</xsl:for-each>
</head>
<body>


<div id="mainbox"><xsl:call-template name="Main_Default"/></div>

<div id="bottombox"><xsl:call-template name="Bottom_Default"/></div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


2. main_default.xsl: included in default.xsl
********************************************
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:include href="main_body.xsl"/>

<xsl:template name="Main_Default">
<div id="mainbody"><xsl:call-template name="Main_Body"/></div>
</xsl:template>
</xsl:stylesheet>

3. main_body.xsl: included in main_default.xsl
**********************************************
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="Main_Body">
<div ="test">test</div>
</xsl:template>
</xsl:stylesheet>

4. 1+2+3 result as:
******************
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xml:lang="nl" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link rel="stylesheet" type="text/css" media="screen" href="/_backend/style/profiles/default/http/css/default.css"/>
</head>
<body>
<div id="mainbox">
    <div id="mainbody" xmlns="">
        <div id="test">test</div>
    </div>
    <div id="mainheader" xmlns="">header</div>
    <div id="mainfooter" xmlns="">footer</div>
</div>

</body>
</html>

5. the result I want:
*********************
....
<body>
<div id="mainbox">
    <div id="mainbody">
        <div id="test">test</div>
    </div>
    <div id="mainheader">header</div>
    <div id="mainfooter">footer</div>
</div>
</body>
.....
 
Old November 23rd, 2004, 12:17 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

It's a bit complicated...

In your main stylesheet you declare a default namespace, xmlns="http://www.w3.org/1999/xhtml" and this applies to all unprefixed elements within that stylesheet. The included documents do not have this so the elements are in no namespace so the processor must undeclare the namespace. To correct it you need to declare the default namespace in all the stylesheets, e.g. in main_default.xsl then have:
Code:
<xsl:template name="Main_Default" xmlns="http://www.w3.org/1999/xhtml">
Alternatively you can specify a namespace on the elements when you declare them,
Code:
<div id="mainbody" xmlns="http://www.w3.org/1999/xhtml">
.

By the way your output method is not html but xml.

--

Joe (Microsoft MVP - XML)
 
Old November 23rd, 2004, 12:24 PM
Authorized User
 
Join Date: Jun 2003
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Kabe
Default

thx a lot !!!





Similar Threads
Thread Thread Starter Forum Replies Last Post
escaping of characters in xsl:attribute pramod Classic ASP XML 1 September 12th, 2008 09:11 AM
Soap Error : Attribute xmlns must be declared RatanKumar XML 0 December 4th, 2006 08:07 PM
XSL Attribute ID jonty XSLT 1 March 28th, 2006 03:53 PM
select childnode of a node with xmlns:xsl attribut beaster XSLT 3 January 13th, 2005 12:29 PM
onClick as xsl attribute? mlaba XSLT 1 September 10th, 2004 02:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.