Hi
I am new at using XML and XSL... and am breaking my head and the
keyboard because of a simple problem...

My XMl file is
<?xml version="1.0" standalone="yes"?>
<CardTransacts>
<CardTransactions>
<card_transaction_id>123</card_transaction_id>
<description_of_charge>abc</description_of_charge>
<process_date>2003-09-06T00:00:00.0000000+05:30</process_date>
<bill_amount>111</bill_amount>
<passenger_name>aa</passenger_name>
</CardTransactions>
...
...
</CardTransacts>

My xsl file is
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h3>Card Transformed</h3>
<table border="2">
<tr>
<td align="left">Card_Transaction_ID</td>
<td align="left">Passenger_Name</td>
<td align="left">Description_of_Charge</td>
<td align="left">Bill_Amount</td>
<td align="left">Process_Date</td>
</tr>
<xsl:for-each select="CardTransacts/CardTransactions">
<xsl:sort select="card_transaction_id" order="ascending"/>
<tr>
<td><xsl:value-of select="card_transaction_id"/></td>
<td><xsl:value-of select="passenger_name"/></td>
<td><xsl:value-of select="description_of_charge"/></td>
<td><xsl:value-of select="bill_amount"/></td>
<td><xsl:value-of select="process_date"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


My Javascript code is

objXMLDoc = new ActiveXObject("MSXML2.DomDocument.3.0");
objXMLDoc.async = false;
// This is necessary to use XPath in selectSingleNode and selectNodes methods
// For backwards compatibility, XSL Patterns are default.
objXMLDoc.setProperty("SelectionLanguage", "XPath");
objXMLDoc.resolveExternals = false;
objXMLDoc.validateOnParse = false;
objXMLDoc.load(strXMLFileName);
objXSLDoc = new ActiveXObject("MSXML2.FreeThreadedDomDocument.3.0");
objXSLDoc.async = false;
objXSLDoc.resolveExternals = false;
objXMLDoc.validateOnParse = false;
objXSLDoc.load(strXSLFileName);
objXSLTemplate = new ActiveXObject("MSXML2.XSLTemplate.3.0");
objXSLTemplate.stylesheet = objXSLDoc;
objXSLProcessor = objXSLTemplate.createProcessor(); objXSLProcessor.input = objXMLDoc;
objXSLProcessor.transform(); Results.innerHTML = objXSLProcessor.output;

However an error is being thrown at
objXSLTemplate.stylesheet = objXSLDoc;

When I used ASP.Net instead of javascript I got the error
'Member not found'

Could somebody throw some light on this?

There are nothing wrong with XML and XSLT and jscript fragment has no obvious mistakes. Nevertheless, perhaps I know the answer:

First, I assume that an element with an ID=Results exists somewhere in the HTML body, because I cannot find any declaration of the variable 'Results'.

Second, I suspect that jscript fragment was written inside

<script></script>

not being part of any function.

It means that at the time of code execution the entire page was not yet loaded entirely and document's elements were not available.

A simple solution, assign output to a string variable, e.g.,
x = objXSLProcessor.output and then add
<script>document.write(x)</script> where needed

Alternatively, wrap all or just some of the statements into the function and call it later,

e.g.,  <script> function getResults() { .... }</script></head>
<body onLoad="getResults()"><div id="Results"></div></body></html>

This corrected HTML file (with a second solution) is shown below.
That's it.
AZ
****************************

<html><head>
<script>
function getResults() { //////////////////////
objXMLDoc = new ActiveXObject("MSXML2.DomDocument.3.0");
objXMLDoc.async = false;
// This is necessary to use XPath in selectSingleNode and selectNodes methods
// For backwards compatibility, XSL Patterns are default.
objXMLDoc.setProperty("SelectionLanguage", "XPath");
objXMLDoc.resolveExternals = false;
objXMLDoc.validateOnParse = false;
objXMLDoc.load('test.xml'); //////////////////
objXSLDoc = new ActiveXObject("MSXML2.FreeThreadedDomDocument.3.0");
objXSLDoc.async = false;
objXSLDoc.resolveExternals = false;
objXMLDoc.validateOnParse = false;
objXSLDoc.load('test.xsl'); /////////////////
objXSLTemplate = new ActiveXObject("MSXML2.XSLTemplate.3.0");
objXSLTemplate.stylesheet = objXSLDoc;
objXSLProcessor = objXSLTemplate.createProcessor();
objXSLProcessor.input = objXMLDoc;
objXSLProcessor.transform();
Results.innerHTML = objXSLProcessor.output;
}        ////////////////
</script>
</head><body onLoad="getResults()">
<div id="Results"></div>
</body></html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.