•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the XML, XSLT and XPATH section within the Software Development category of DaniWeb, a massive community of 397,786 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,368 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our XML, XSLT and XPATH advertiser:
Views: 2566 | Replies: 1
![]() |
•
•
Join Date: Jul 2006
Posts: 10
Reputation:
Rep Power: 3
Solved Threads: 0
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?
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 10:06 am.
•
•
Join Date: Aug 2006
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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]
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]
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb XML, XSLT and XPATH Marketplace
- XML or XSL or What?? (XML, XSLT and XPATH)
- XML Transformations (XML, XSLT and XPATH)
- xsl-fo (DaniWeb Community Feedback)
- Access unqualified XML element (C#)
- ASP.NET - session objects Problem (ASP.NET)
- Transforming XML with XSLT (HTML and CSS)
Other Threads in the XML, XSLT and XPATH Forum
- Previous Thread: traversing XML with DOM, java
- Next Thread: get XML from Attributes


Linear Mode