[xsl] Go Back Function When Using MSXML Transforms

Subject: [xsl] Go Back Function When Using MSXML Transforms
From: "Beverly L. Parmelee" <parmelee@xxxxxxxxxxxxx>
Date: Fri, 21 Nov 2003 22:15:31 -0500
Is there a way to get the browser's go back function to work when using MSXML transforms? The example code below (4 files) works fine for moving forward through the transformations, so I'm looking for how to modify it for going back. Thanks!

index.xsd..................
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"; elementFormDefault="qualified">
<xsd:element name="INVENTORY">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ITEM" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ITEM_NO" type="xsd:positiveInteger"/>
<xsd:element name="SUMMARY_INFO" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>


index.xml...............................
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml:stylesheet type="text/xsl" href="index.xsl"?>
<INVENTORY xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:noNamespaceSchemaLocation="index.xsd">
<ITEM>
<ITEM_NO>1</ITEM_NO>
<SUMMARY_INFO>Summary Info</SUMMARY_INFO>
</ITEM>
<ITEM>
<ITEM_NO>2</ITEM_NO>
<SUMMARY_INFO>Summary Info</SUMMARY_INFO>
</ITEM>
<ITEM>
<ITEM_NO>3</ITEM_NO>
<SUMMARY_INFO>Summary Info</SUMMARY_INFO>
</ITEM>
</INVENTORY>


index.xsl.....................................
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<script language="javascript" type="text/javascript">
<xsl:comment> //
function transform(xsl_page,user_choice)
{
var IE4, NS4, W3C;
IE4 = (document.all) ? true : false;
NS4 = (document.layers) ? true : false;
// else document.getElementById and !document.all
W3C = (document.getElementById) ? true : false;


// load the called stylesheet
if (IE4)
{
var xsltOldProcessor = new ActiveXObject("Msxml2.XSLTemplate.4.0");
var xslNewDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
}
else
{
var xsltOldProcessor = new xsltProcessor();
var xslNewDoc = document.implementation.createDocument("", "", null);
xslNewDoc.addEventListener("load", onload, false);
}
var xslNewProcessor;


                        xslNewDoc.async = false;
                        xslNewDoc.resolveExternals = false;
                        xslNewDoc.load(xsl_page);

if ( xslNewDoc.parseError.errorCode != 0 )
{
alert("You have error " + xslNewDoc.parseError.reason);
}
else
{
if (IE4)
{
var xmlOldDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
}
else
{
var xmlOldDoc = document.implementation.createDocument("", "", null);
xmlOldDoc.addEventListener("load", onload, false);
}


                             // load the calling stylesheet
                             xsltOldProcessor.stylesheet = xslNewDoc;
                             xmlOldDoc.async = false;
                             xmlOldDoc.resolveExternals = false;
                             xmlOldDoc.load("index.xml");

if (xmlOldDoc.parseError.errorCode != 0)
{
alert("You have error " + xmlOldDoc.parseError.reason);
}
else
{
xslNewProcessor = xsltOldProcessor.createProcessor();
xslNewProcessor.input = xmlOldDoc;
// pass the function parameter to the stylesheet and transform
xslNewProcessor.addParameter("user_input", user_choice);
xslNewProcessor.transform();


if (IE4)
{
if (document.all)
{ document.body.innerHTML = xslNewProcessor.output;
}
}
else if (NS4)
{
if (document.lyrBackground.document)
{ document.body.innerHTML = xslNewProcessor.output;
}
}
else
{
if (document.getElementById)
{ document.body.innerHTML = xslNewProcessor.output;
}
}
}
}
}
// End</xsl:comment>
</script>
</head>
<body leftmargin="0" marginwidth="0" topmargin="0">
<xsl:variable name="item" select="1"/>
<xsl:copy-of select="INVENTORY/ITEM[ITEM_NO=$item]/SUMMARY_INFO"/>
<xsl:copy-of select="$item"/>
<br/>
<a>
<xsl:attribute name="href">#</xsl:attribute>
<xsl:attribute name="onclick">
<xsl:text>transform('detail.xsl',</xsl:text>
<xsl:value-of select="$item"/>
<xsl:text>)</xsl:text>
</xsl:attribute>
Go To Item #<xsl:value-of select="INVENTORY/ITEM[ITEM_NO=$item]/ITEM_NO"/> Detail
</a>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


detail.xsl...............................................
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:param name="user_input"/>
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<body leftmargin="0" marginwidth="0" topmargin="0">
<a>
<xsl:attribute name="href">#</xsl:attribute>
<xsl:attribute name="onclick">
<xsl:text>transform('detail.xsl',</xsl:text>
<xsl:value-of select="$user_input+1"/>
<xsl:text>)</xsl:text>
</xsl:attribute>
Go To Item #<xsl:value-of select="INVENTORY/ITEM[ITEM_NO=$user_input+1]/ITEM_NO"/> Detail
</a>
</body>
</html>
</xsl:template>
</xsl:stylesheet>




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


Current Thread