Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I can't get around the error: "Prefix 'xmlns' is not defined." 2

Status
Not open for further replies.

Sniipe

Programmer
Oct 9, 2006
115
IE
I have an xslt file which can be called 2 ways;
1) the user clicked on excel download
2) the user clicked on html download

I can get the html download working, but not excel download.

When I try to add in the code I want, neither work and I get the same error:
"Prefix 'xmlns' is not defined."

This is the code:

Code:
<html>
<xsl:choose>
	<xsl:when test="$reportType = 'HTML'">
		<xsl:call-template name="HTMLStyle"/>
	</xsl:when>
	<xsl:otherwise>		
		<xsl:attribute name="xmlns">
[URL unfurl="true"]http://www.w3.org/TR/REC-html40[/URL]	
		</xsl:attribute>
		<xsl:attribute name="xmlns:o">
urn:schemas-microsoft-com:office:office
		</xsl:attribute>
		<xsl:attribute name="xmlns:x">
urn:schemas-microsoft-com:office:excel
		</xsl:attribute>
		<xsl:call-template name="ExcelStyle"/>
	</xsl:otherwise>
</xsl:choose>
<body>
	<h1>MAIN SITE</h1>

I need the html to look like this when excel is being used (denoted by the otherwise from <xsl:call-template name="HTMLStyle"/>):
<html xmlns:eek:="urn:schemas-microsoft-com:eek:ffice:eek:ffice" xmlns:x="urn:schemas-microsoft-com:eek:ffice:excel" xmlns="
And when its HTML; I don't need it to look like that.

Any help or pointers would be appreciated. Thanks
 
[1] It is unclear the namespace of <body> onward which may be a big chunk of tags. It might have relevence because I would have in mind to start with establishing the <html> on its own for the two different cases.

[2] To similify the reasoning, suppose I put all the body fragment into a common named template "common".
[tt]
[blue]<xsl:template name="common">
<body>
<h1>MAIN SITE</h1>
<!-- etc etc including possibly even xsl:apply-templates -->
</body>
</xsl:template>[/blue]
[/tt]
[3] Then the part of establishing the html tag is more involved.

[3.1] In the stylesheet declaration, declare the desired default namespace for the html for excel with some arbitrary prefix, say "d", _and_ at the same time, let the same as the default namespace of the xsl as well. Both bits are important.
[tt]
<xsl:stylesheet version="1.0" xmlns:xsl=" [blue]xmlns=" xmlns:d="[/blue]
>
[/tt]
[3.2] The declare an xsl:namespace-alias statement at the top level.
[tt]
[blue]<xsl:namespace-alias stylesheet-prefix="d" result-prefix="#default" />[/blue]
[/tt]
[3.3] In the xsl:choose, it is called outside the setup of html tag. Here, there are some uncertainties to the detail, but, the big picture I see is this.
[tt]
<xsl:choose>
<xsl:when test="$reportType = 'HTML'">
[blue]<xsl:element name="html">[/blue]
<xsl:call-template name="HTMLStyle"/>
[blue]<xsl:call-template name="common" />[/blue]
[blue]</xs:element>[/blue]
</xsl:when>
<xsl:eek:therwise>
[blue]<d:html
xmlns:eek:="urn:schema-microsoft-com:eek:ffice:eek:ffice"
xmlns:x="urn:schema-microsoft-com:eek:ffice:excel"
>[/blue]
[blue]<xsl:call-template name="ExcelStyle"/>[/blue]
<xsl:call-template name="common" />
</d:html>
</xsl:eek:therwise>
</xsl:choose>
[/tt]
[4] There is some uncertainty as to the repercussion on the $reportType='HTML' part, but the otherwise part should go more or less like shown above.
 
tsuji, u are invaluable. this is the second or third time you have helped me out. Thank you for your post. I got it working.
 
The thankfulness is reciprocal. It is always a pleasure to answer good questions reasonably formulated to a scale still being answerable (that is not easy to do), though I do not say thanks all the time.
 
tsuji said:
It is always a pleasure to answer good questions reasonably formulated...
I agree...and add my star. tsuji is not only helping sniipe, but also dozens, perhaps hundreds, of others. And it is all in response to good questions reasonably formulated!

Tom Morrison
 
the man (a presumption) is a living legend! Yes, I agree a well answered post really helps people later on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top