xsl-list
[Top] [All Lists]

Re: Why doesn't exclude-result-prefixes rid me of xmlns=""?

2004-04-13 09:03:32
I've found that it only puts this in when you use xsl:copy (it aught to have
a parameter to avoid that, I think). Here is my solution:

  <xsl:template match="xhtml:*">
    <!-- This is an identity template for XHTML elements -->
    <!-- xsl:copy is no good because it explicitly gives the namespace
uri -->
    <xsl:element name="{name(.)}">
      <xsl:for-each select="@*">
        <xsl:attribute name="{name(.)}">
          <xsl:value-of select="."/>
        </xsl:attribute>
      </xsl:for-each>
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>

as opposed to:

<xsl:template match="xhtml:*">
 <xsl:copy>
   <xsl:apply-templates />
 </xsl:copy>
</xsl:template>

I don't suppose the xmlns= would hurt to have in your xhtml output, but I
just wanted a 1:1 transformation in all cases, probably the same with you.

-Jeff

----- Original Message ----- 
From: "Michael Kay" <mhk(_at_)mhk(_dot_)me(_dot_)uk>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Tuesday, April 13, 2004 2:41 AM
Subject: RE: [xsl] Why doesn't exclude-result-prefixes rid me of xmlns=""?


You have created an <html> element in the "http://www.w3.org/1999/xhtml";
namespace, and within it you have created a <div> element that is in no
namespace. The xmlns="" is generated in order to ensure that the <div>
element is in no namespace, which is what you requested. If you want the
<div> element to be in the XHTML namespace, you need to ensure that the
<div> element in the stylesheet has an
xmlns="http://www.w3.org/1999/xhtml";
declaration in scope.

Responding to the question in your subject line, exclude-result-prefixes
is
provided to help you get rid of namespaces declarations that are not used
in
the result document. It will never get rid of namespace declarations that
are generated to put elements in the right namespace.

Michael Kay

-----Original Message-----
From: Michael Terry [mailto:formido(_at_)mac(_dot_)com]
Sent: 13 April 2004 08:05
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Why doesn't exclude-result-prefixes rid me of xmlns=""?

Hi,

After searching Google, I figured out how to
exclude-result-prefixes,
but I'm still getting an unwanted 'xmlns=""' in one of my outputted
divs. Can someone tell me why?

Following on, I've included excerpts from the source, the
script, and
the result. At the bottom, I pasted in the browser display from the
result of running the processor-version.xsl on itself, plus links to
the relevant full texts, should they be necessary.

--------------------------------------
dictionary.xmloutline (source excerpt)
--------------------------------------
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE oo:outline PUBLIC "-//omnigroup.com//DTD OUTLINE 2.0//EN"
"xmloutline-v2.dtd">
<outline
xmlns:oo="http://www.omnigroup.com/namespace/OmniOutliner/v2";
version="1.0">
   <oo:columns>

... snip ...

  <oo:root background-color='#ffffff' alternate-color='#d6ffed'>
     <oo:item expanded="yes">
       <oo:values>
         <oo:rich-text><oo:p alignment="left"><oo:font face="Monaco"
size="10">OmniWeb:</oo:font></oo:p></oo:rich-text>
       </oo:values>
       <oo:children>
         <oo:item expanded="yes">
           <oo:values>
             <oo:rich-text><oo:p alignment="left"><oo:font
face="Monaco"
size="10">classes:</oo:font></oo:p></oo:rich-text>
           </oo:values>
           <oo:children>
             <oo:item expanded="yes">
               <oo:values>
                 <oo:rich-text><oo:p alignment="left"><oo:font
face="Monaco" size="10">application:</oo:font></oo:p></oo:rich-text>
               </oo:values>
               <oo:children>
                 <oo:item expanded="yes">
                   <oo:values>
                     <oo:rich-text><oo:p alignment="left"><oo:font
face="Monaco" size="10">commands:</oo:font></oo:p></oo:rich-text>
                   </oo:values>
                   <oo:children>
                     <oo:item expanded="yes">
                       <oo:values>
                         <oo:rich-text><oo:p><oo:font face="Monaco"
size="10">activate:</oo:font></oo:p></oo:rich-text>
                       </oo:values>
                       <oo:children>

--------------------------------------
format_dictionary.xsl (full text)
--------------------------------------
<?xml version="1.0"?>

<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:oo="http://www.omnigroup.com/namespace/OmniOutliner/v2";
exclude-result-prefixes="oo">

<xsl:output
method="xml"
indent="yes"

doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>

<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml";
xml:lang="en" lang="en">
<head>
<title>OmniWeb AppleScript Documentation</title>
<meta http-equiv="Content-Type"
content="text/html;
charset=us-ascii"/>
</head>
<body>
<xsl:apply-templates select="outline/oo:root"/>
</body>
</html>
</xsl:template>

<xsl:template match="oo:root">
<xsl:apply-templates select="oo:item"/>
</xsl:template>

<xsl:template match="oo:item">
<div>
<xsl:value-of select="./oo:values/oo:rich-text/oo:p"/>
<xsl:apply-templates select="oo:children/oo:item"/>
</div>
</xsl:template>

</xsl:stylesheet>

--------------------------------------
dictionary.html (result excerpt)
--------------------------------------
<?xml versioasdfsan="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
<title>OmniWeb AppleScript Documentation</title>
<meta http-equiv="Content-Type" content="text/html;
charset=us-ascii" />
</head>
<body>
<div
xmlns="">OmniWeb:<div>classes:<div>application:<div>commands:
<div>activate:<div>activate</div>
</div>
<div>count:<div>count</div>
<div>count it each browser</div>
<div>count each browser</div>
</div>

--------------------------------------
processor version info
--------------------------------------
Vendor: Apache Software Foundation
Vendor URL: http://xml.apache.org/xalan-c

--------------------------------------
links to full texts
--------------------------------------
<http://homepage.mac.com/formido/dictionary.xmloutline>
<http://homepage.mac.com/formido/format_dictionary.xsl>
<http://homepage.mac.com/formido/dictionary.html>
<http://homepage.mac.com/formido/processor_version_info.html>

Mike


--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--




--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--