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

XML and XSL in same FILE 1

Status
Not open for further replies.

lebartha

Programmer
Mar 21, 2007
3
0
0
US
Hello everyone,

I was wondering if somebody could help me out.
We want to include our XML file in the same file that that has the XSL. It works perfectly in Firefox (2) but IE 6 or 7 cannot find the XML when it tries to parse it with the XSL code, but at the end it just dumps it on the screen as text. What I mean is the way it should look with XSL is not displayed, but the raw XML is. In firefox it works flawlessly.

Anyone could help to give me some pointers how to accomplish this (but no remarks why I shouldn't please).

Here is my XML and XSL file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet version="2.0" type="text/xsl" href="#stylesheet"?>
<!DOCTYPE d3 [
<!ATTLIST xsl:stylesheet id ID #REQUIRED>
]>
<d3>
<xsl:stylesheet id="stylesheet" version="2.0" xmlns:xsl="<xsl:eek:utput method="html" encoding="ISO-8859-1" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="<xsl:template match="ROOT">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>PUC Courses</title>
<link rel="stylesheet" href=" type="text/css" media="print" />
<style type="text/css">

table.sortable a.sortheader {
background-color:#3A6EA5;
color:#ffffff;
text-decoration: none;
display: block;
}

table.sortable span.sortarrow {
color: black;
text-decoration: none;
}

th {
background-color: #3A6EA5;
color: #ffffff;
text-align: left;
vertical-align: text-top;
padding: 4px;
font-family: "Trebuchet MS", Verdana, sans-serif;
font-size: 11px;
border-color: #3A6EA5;
border-width: 0px;
border-style: solid;
}

td {
background-color: #EEF0EB;
color: #000000;
text-align: left;
vertical-align: text-top;
padding: 4px;
font-family: "Trebuchet MS", Verdana, sans-serif;
font-size: 10px;
border-color: #989898;
border-width: 0px;
border-style: dashed;
}

td.menuon { background-color: #787878; color: #ffffff; border-style: solid;}
td.menuoff {
background-color: #EEF0EB;
color: #000000;
text-align: left;
vertical-align: text-top;
padding: 4px;
font-family: "Trebuchet MS", Verdana, sans-serif;
font-size: 10px;
border-color: #989898;
border-width: 0px;
border-style: dashed;
}

body {
font-family: verdana,sans-serif;
font-size: .8em;
background-color: #ffffff;
margin: 0;
}
</style>
<script language="javascript" src="sorttable.js"></script>
</head>
<body>
<table class="sortable" id="2007">
<tr>
<th>Course Type</th>
<th>CODE</th>
<th>DEPT</th>
<th>SUBJT</th>
<th>SPR</th>
<th>Section</th>
<th>Term</th>
<th>Short Title</th>
<th>CREDIT</th>
<th>Faculty Names</th>
<th>Seats Available</th>
<th>Capacity</th>
<th>BLDG</th>
<th>ROOM</th>
<th>BEGIN</th>
<th>DAYS</th>
</tr>
<xsl:for-each select="COURSE.SECTIONS">
<tr>
<td class="menuoff" onmouseover="className='menuon';" onmouseout="className='menuoff';">
<xsl:value-of select="AAA" />
</td>
<td class="menuoff" onmouseover="className='menuon';" onmouseout="className='menuoff';">
<xsl:value-of select="BBB" />
</td>
<td class="menuoff" onmouseover="className='menuon';" onmouseout="className='menuoff';">
<xsl:value-of select="CCC" />
</td>
<td class="menuoff" onmouseover="className='menuon';" onmouseout="className='menuoff';">
<xsl:value-of select="DDD" />
</td>
<td class="menuoff" onmouseover="className='menuon';" onmouseout="className='menuoff';">
<xsl:value-of select="EEE" />
</td>
<td class="menuoff" onmouseover="className='menuon';" onmouseout="className='menuoff';">
<xsl:value-of select="FFF" />
</td>
<td class="menuoff" onmouseover="className='menuon';" onmouseout="className='menuoff';">
<xsl:value-of select="GGG" />
</td>
<td class="menuoff" onmouseover="className='menuon';" onmouseout="className='menuoff';">
<xsl:value-of select="HHH" />
</td>
<td class="menuoff" onmouseover="className='menuon';" onmouseout="className='menuoff';">
<xsl:value-of select="III" />
</td>
<td class="menuoff" onmouseover="className='menuon';" onmouseout="className='menuoff';">
<xsl:value-of select="JJJ" />
</td>
<td class="menuoff" onmouseover="className='menuon';" onmouseout="className='menuoff';">
<xsl:value-of select="KKK" />
</td>
<td class="menuoff" onmouseover="className='menuon';" onmouseout="className='menuoff';">
<xsl:value-of select="LLL" />
</td>
<td class="menuoff" onmouseover="className='menuon';" onmouseout="className='menuoff';">
<xsl:value-of select="MMM" />
</td>
<td class="menuoff" onmouseover="className='menuon';" onmouseout="className='menuoff';">
<xsl:value-of select="NNN" />
</td>
<td class="menuoff" onmouseover="className='menuon';" onmouseout="className='menuoff';">
<xsl:value-of select="OOO" />
</td>
<td class="menuoff" onmouseover="className='menuon';" onmouseout="className='menuoff';">
<xsl:value-of select="PPP" />
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="xsl:stylesheet" />
</xsl:stylesheet>
<ROOT>
<COURSE.SECTIONS>
<AAA>GE1A</AAA>
<BBB>1542</BBB>
<CCC>CA</CCC>
<DDD>BLAH</DDD>
<EEE>1</EEE>
<FFF>02</FFF>
<GGG>BLAH</GGG>
<HHH>2.0</HHH>
<III>Sampres</III>
<JJJ>1</JJJ>
<KKK>25</KKK>
<LLL>PBS</LLL>
<MMM>AF</MMM>
<NNN>5-7</NNN>
<OOO>0AAA</OOO>
<PPP>0AAA</PPP>
</COURSE.SECTIONS>
</ROOT>
</d3>

Thank you
 
I figured it out. IE 5,6,7 does not support embedded XSL in XML. There has to be a trick to do it. I found some examples after searching google for 2 hrs, but none work. There is another way with MSXML. Does anyone have any idea?

Len
 
I played around with it for a while and the MSXML validator claims that the d3 element isn't declared but the </d3> tag was found. May be barking up a dead horse.
 
Hey Harebrain,

I got it to work. It was crazy. After 3 hrs of search on google, i found an ebook from oreilly called XSLT Cookbook.

The example there worked how to combine XSLT and XML into one document that works on both IE and FIREFOX.

Here is their Example:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="selfcontained2.xsl"?>
<xsl:stylesheet xmlns:xsl=" xmlns:pf=" version="1.0">
<xsl:eek:utput method="html"/>
<xsl:attribute-set name="gain-loss-font">
<xsl:attribute name="color">
<xsl:choose>
<xsl:when test="(pf:current - pf:paid) * pf:qty &gt;= 0">black</xsl:when>
<xsl:eek:therwise>red</xsl:eek:therwise>
</xsl:choose>
</xsl:attribute>
</xsl:attribute-set>
<xsl:template match="pf:portfolio">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>My Portfolio</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<h1>Portfolio</h1>
<table border="1" cellpadding="2">
<tbody>
<tr>
<th>Symbol</th>
<th>Current</th>
<th>Paid</th>
<th>Qty</th>
<th>Gain/Loss</th>
</tr>
<xsl:apply-templates/>
</tbody>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="pf:investment">
<tr>
<td>
<xsl:value-of select="pf:symbol"/>
</td>
<td>
<xsl:value-of select="pf:current"/>
</td>
<td>
<xsl:value-of select="pf:paid"/>
</td>
<td>
<xsl:value-of select="pf:qty"/>
</td>
<td>
<font xsl:use-attribute-sets="gain-loss-font">
<xsl:value-of select="format-number((pf:current - pf:paid) * pf:qty, '#,##0.00')"/>
</font>
</td>
</tr>
</xsl:template>
<xso:template xmlns:xso=" match="xsl:stylesheet">
<xso:apply-templates select="pf:portfolio"/>
</xso:template>
<pf:portfolio xmlns=" <pf:investment>
<symbol>IBM</symbol>
<current>72.70</current>
<paid>65.00</paid>
<qty>1000</qty>
</pf:investment>
<investment>
<symbol>JMAR</symbol>
<current>1.90</current>
<paid>5.10</paid>
<qty>5000</qty>
</investment>
<investment>
<symbol>DELL</symbol>
<current>24.50</current>
<paid>18.00</paid>
<qty>100000</qty>
</investment>
<investment>
<symbol>P</symbol>
<current>57.33</current>
<paid>63</paid>
<qty>100</qty>
</investment>
</pf:portfolio>
</xsl:stylesheet>


They pretty much give the XML a namespace and tell the XSL that the same file needs to parse it.

It worked. I just changed a bunch of stuff to make it work for me.

Thanks for the help.

Len
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top