943,936 Members | Top Members by Rank

Ad:
Aug 4th, 2006
0

Help needed in simple app while using XML,XSL

Expand Post »
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?
Last edited by Phoenix777; Aug 4th, 2006 at 11:06 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Phoenix777 is offline Offline
10 posts
since Jul 2006
Aug 11th, 2006
0

Re: Help needed in simple app while using XML,XSL

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 [html]<script></script> [/html] 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,
[html]
e.g., <script> function getResults() { .... }</script></head>
<body onLoad="getResults()"><div id="Results"></div></body></html>
[/html]
This corrected HTML file (with a second solution) is shown below.
That's it.
AZ
****************************
[html]
<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>
[/html]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
az195 is offline Offline
1 posts
since Aug 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in XML, XSLT and XPATH Forum Timeline: traversing XML with DOM, java
Next Thread in XML, XSLT and XPATH Forum Timeline: get XML from Attributes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC