This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Adding xsl:include seems to stop java filter working


I hope someone out there can help me, as I am new to XSLT.

Using Chris Bayes excellent "beer" pages as an example, I have created a
.xsl stylesheet which uses two different modes for variable formatting
of the output.  But I have a problem when I add any <xsl:include>
statements, in that the javascript assigning of the stylesheet to the
new ActiveX object with the line "tem.stylesheet = s" seems to fail.
Without the xsl:include, I can switch between the 2 modes quite happily.

This is a cut-down example of the problem code, with apologies for the
large amount of text included:

========================================================================
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0" >
<!--  Uncommenting the line below causes the problem
<xsl:include href="colours.xsl"/>
-->
<!-- These 3 lines are included to make it work without the xsl:include
-->
<xsl:variable name="bodybg">#CCCCFF</xsl:variable>
<xsl:variable name="cellbg">#C0C0C0</xsl:variable>
<xsl:variable name="lablbg">#F5F5F5</xsl:variable>

<xsl:param name="MyMode"/>

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

<script LANGUAGE="JavaScript"><xsl:comment><![CDATA[
function filter(MyMode)
{
	try{
		var s = new
ActiveXObject("MSXML2.FreeThreadedDOMDocument");
		var x = document.XMLDocument;
		if (x == null){
			x = navigator.XMLDocument;
			s.loadXML(navigator.XSLDocument.xml);
		}else{
			s.loadXML(document.XSLDocument.xml);
		}
		var tem = new ActiveXObject("MSXML2.XSLTemplate");
alert("Assigning Stylesheet");
		tem.stylesheet = s;
alert("Stylesheet assigned");
		var proc = tem.createProcessor();
		proc.addParameter("MyMode", MyMode);
		proc.input = x;
		proc.transform();
		var str = proc.output;
		var newDoc = document.open("text/html", "replace");
		newDoc.write(str);
		navigator.XMLDocument = x;
		navigator.XSLDocument = s;
		newDoc.close();
		}
	catch(exception){
		}
}
]]></xsl:comment></script>
   </head>

<body>
   <xsl:attribute name="bgcolor"><xsl:value-of
select="$bodybg"/></xsl:attribute>
   <xsl:choose>
	<xsl:when test="$MyMode">
	   <xsl:apply-templates select="." mode="Update"/>
	</xsl:when>
	<xsl:otherwise>
	   <xsl:apply-templates select="." mode="List"/>
	</xsl:otherwise>
   </xsl:choose>
</body>
</html>
</xsl:template>

<xsl:template match="/" mode="List">
   <table width="150" height="150">
      <tr>
    	<td height="41" width="226">
         <xsl:attribute name="bgcolor"><xsl:value-of
select="$cellbg"/></xsl:attribute>
	   <xsl:variable name="MyMode" select="'Update'"/>
	   <xsl:attribute name="onclick">filter('<xsl:value-of
select="$MyMode"/>');</xsl:attribute>
		<u><span style="cursor:hand;">Switch  modes</span></u>
	</td>
      </tr>
   </table>
</xsl:template>

<xsl:template match="/" mode="Update">
   <table width="450" height="150">
     <tr>
       <td height="41" width="335">Sign-In Name
         <xsl:attribute name="bgcolor"><xsl:value-of
select="$lablbg"/></xsl:attribute>
       </td>
       <td height="41" width="210">
         <xsl:attribute name="bgcolor"><xsl:value-of
select="$cellbg"/></xsl:attribute>
	   <input type="text" name="reglogin"  size="43" maxlength="64">
		<xsl:attribute name="value">
		   <xsl:value-of
select="normalize-space(Results/SigninName)"/>
		</xsl:attribute>
	   </input>
      </td>
    <td height="41" align="center" width="210">
      <xsl:attribute name="bgcolor"><xsl:value-of
select="$cellbg"/></xsl:attribute>
	   <input type="button" name="CANCEL" value="Cancel">
		<xsl:attribute
name="onclick">filter('');</xsl:attribute>
	   </input>
	</td>
     </tr>
   </table>
</xsl:template>
</xsl:stylesheet>
======================================================================

This code works correctly with this xml file

<?xml version="1.0"?>
<?xml-stylesheet href="test.xsl" type="text/xsl"?>
<Results>
<SigninName>
tmaxted
</SigninName>
</Results>

but when I comment out the 3 lines defining the colours and uncomment
the xsl:include line for the colours.xsl, I only get the first alert
from the Javascript "filter".

Content of colours.xsl file:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
   <xsl:variable name="bodybg">#CCCCFF</xsl:variable>
   <xsl:variable name="tablbg">#C0C0C0</xsl:variable>
   <xsl:variable name="cellbg">#C0C0C0</xsl:variable>
   <xsl:variable name="lablbg">#F5F5F5</xsl:variable>
</xsl:stylesheet>


Any help you could give me would be appreciated.  BTW I am using IE 5.0
and MSXML 2 version 3

Regards

Trevor Maxted, Senior Development Consultant, Valid Information Systems
e-mail: tmaxted@valinf.com

All of the opinions and views expressed in this message are the personal
views of the sender, and do not necessarily represent in any way the
official position of Valid Information Systems




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]