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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xml/xslt doesn't work

Status
Not open for further replies.

carvin5string

IS-IT--Management
Apr 8, 2004
10
US
So here I am learning XML, just started this week with the Dummys XML book. I'm working out the examples, finding some don't work as described (see my other post for another example). This time I have an xml file and an xslt file to transform it to html. When viewed in Netscape and Mozilla I see all the text in one blob across the top of the window, the xslt formatting instructions completely ignored. In IE it gives an error:

The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
Keyword xsl:template may not be used here.

Any suggestions on what I should be looking for to fix this problem? Or is it just the browsers don't support xslt enough yet?

Thanks,
Chip

Below is the xslt I am using, which validates as well-formed.
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] xmlns="[URL unfurl="true"]http://www.w3.org/TR/REC-html40">[/URL]
	<xsl:output method="xml" encoding="iso-8859-1"/>
	<xsl:template match="recipe">
		<html>
			<head>
				<title>
					<xsl:value-of select="recipe/title"/>
				</title>
			</head>
			<body>
				<xsl:apply-templates/>
			</body>
			<xsl:template match="recipe/title">
				<h1>
					<xsl:apply-templates/>
				</h1>
			</xsl:template>
			<xsl:template match="recipe/ingredients">
				<h2>Ingredients</h2>
				<ul>
					<xsl:for-each select="item">
						<li>
							<xsl:apply-templates/>
						</li>
					</xsl:for-each>
				</ul>
			</xsl:template>
			<xsl:template match="recipe/cookinginstructions">
				<h2>Cooking Instuctions</h2>
				<p>
					<xsl:apply-templates/>
				</p>
			</xsl:template>
			<xsl:template match="recipe/servinginstructions">
				<h2>Serving Instructions</h2>
				<p>
					<xsl:apply-templates/>
				</p>
			</xsl:template>
		</html>
	</xsl:template>
</xsl:stylesheet>

--
Chip
 
Try changing this line:
[tt]<xsl:eek:utput method="xml" encoding="iso-8859-1"/>[/tt]
To this:
[tt]<xsl:eek:utput method="html" encoding="iso-8859-1"/>[/tt]

Chip H.



If you want to get the best response to a question, please check out FAQ222-2244 first
 
You cannot put an <xsl:template/> as a subnode of another <xsl:template/>
 
Thanks for the replies. I don't know which is more correct becuase it still doesn't display as expected. I Netscape all the body text is displayed in one paragraph at the top of the window and in IE I see the color-coded source code. Though no error messages this time.

--
Chip
 
OK, try this:
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] xmlns="[URL unfurl="true"]http://www.w3.org/TR/REC-html40">[/URL]
   <xsl:output method="html" encoding="iso-8859-1" />

 <xsl:template match="/recipe">
  <html>

   <head>
    <title>
     <xsl:value-of select="title" />
    </title>
   </head>

   <body>
    <xsl:apply-templates />
   </body>
  </html>

 </xsl:template>

 <xsl:template match="title">
  <h1>
   <xsl:apply-templates />
  </h1>
 </xsl:template>

 <xsl:template match="ingredients">
  <h2>Ingredients</h2>
  <ul>
   <xsl:for-each select="item">
    <li>
     <xsl:apply-templates />
    </li>
   </xsl:for-each>
  </ul>
 </xsl:template>

 <xsl:template match="cookinginstructions">
  <h2>Cooking Instuctions</h2>
  <p>
   <xsl:apply-templates />
  </p>
 </xsl:template>

 <xsl:template match="servinginstructions">
  <h2>Serving Instructions</h2>
  <p>
   <xsl:apply-templates />
  </p>
 </xsl:template>
</xsl:stylesheet>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top