Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 30th, 2009, 06:44 PM
Registered User
 
Join Date: Mar 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Is there a way to store XML text in a javascript variable?

OK, here's my situation - I am working on making a dynamic table using a xls file with an xml file. Trying to get it to do anything dynamic using XSLT has been very difficult for me, as I never know what I can or can't do.

Here's the trimmed down XML file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="logger.xsl"?>
<!-- !DOCTYPE log SYSTEM "logger.dtd" -->
<log>

<record>
<date>2009-02-23T08:46:52</date>#time and date to the milisecond that this event occured
<millis>1235400412162</millis>#also the date and time just in millisecond format. this is the number of milliseconds from jan 1 1970
<sequence>0</sequence>
<logger>com.dtw.bpo.Application</logger>
<level>FINER</level>
<class>com.dtw.bpo.Application</class>
<method>main</method>
<thread>10</thread>
<message>ENTRY</message>
</record>
<record>
<date>2009-02-23T08:46:52</date>
<millis>1235400412256</millis>
<sequence>1</sequence>
<logger>com.dtw.bpo.Application</logger>
<level>INFO</level>
<class>com.dtw.bpo.Application</class>
<method>main</method>
<thread>10</thread>
<message>Application App is initializing...</message>
</record>

<record>
<date>2009-02-23T08:46:52</date>
<millis>1235400412271</millis>
<sequence>2</sequence>
<logger>com.dtw.util.LoggingMgr</logger>
<level>FINER</level>
<class>com.dtw.util.LoggingMgr</class>
<method>getInstance</method>
<thread>10</thread>
<message>ENTRY</message>
</record>
<record>
<date>2009-02-23T08:46:52</date>
<millis>1235400412271</millis>
<sequence>2</sequence>
<logger>com.dtw.util.LoggingMgr</logger>
<level>FINER</level>
<class>com.dtw.util.LoggingMgr</class>
<method>getInstance</method>
<thread>10</thread>
<message>ENTRY</message>
</record>

<record>
<date>2009-02-23T08:46:52</date>
<millis>1235400412272</millis>
<sequence>3</sequence>
<logger>com.dtw.util.LoggingMgr</logger>
<level>FINER</level>
<class>com.dtw.util.LoggingMgr</class>
<method>LoggingMgr</method>
<thread>11</thread>
<message>ENTRY</message>
</record>

<record>
<date>2009-02-23T08:46:52</date>
<millis>1235400412271</millis>
<sequence>4</sequence>
<logger>com.dtw.util.LoggingMgr</logger>
<level>FINER</level>
<class>com.dtw.util.LoggingMgr</class>
<method>loadProperties</method>
<thread>10</thread>
<message>ENTRY</message>
</record>
<record>
<date>2009-02-23T08:46:52</date>
<millis>1235400412271</millis>
<sequence>5</sequence>
<logger>com.dtw.util.PropertiesMgr</logger>
<level>SEVERE</level>
<class>com.dtw.util.PropertiesMgr</class>
<method>getInstance</method>
<thread>10</thread>
<message>Initalizing PropertiesMgr in getInstance() method</message>
</record>
<record>
<date>2009-02-23T08:46:52</date>
<millis>1235400412287</millis>
<sequence>6</sequence>
<logger>com.dtw.util.PropertiesMgr</logger>
<level>FINER</level>
<class>com.dtw.util.PropertiesMgr</class>
<method>init</method>
<thread>10</thread>
<message>ENTRY</message>
</record>
<record>
<date>2009-02-23T08:46:52</date>
<millis>1235400412287</millis>
<sequence>7</sequence>
<logger>com.dtw.util.PropertiesMgr</logger>
<level>FINER</level>
<class>com.dtw.util.PropertiesMgr</class>
<method>loadProperties</method>
<thread>10</thread>
<message>ENTRY</message>
</record>
</log>

Here's the .xls file i've been putting together:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>

<head>
<script type="text/javascript">
var rowID;
rowID=1
</script>


<script type="text/javascript">
function insRow(rowID)
{
var x=document.getElementById('myTable').insertRow(row ID)
var y=x.insertCell(0)
var z=x.insertCell(1)
z.colSpan=8;
y.innerHTML=""
z.innerHTML=""
}
</script>
</head>

<body>

<h1>Application Log</h1>

<script type="text/javascript">
document.write("<h1>Application Log</h1>);
</script>

Date: <input type="text" name="BeginDate" size="20"/> to <input type="text" name="EndDate" size="20"/>
<input type="button"
onclick="myfunction(BeginDate, EndDate)"
value="Filter"/>
<br />
<br />
Milliseconds: <input type="text" name="BeginMillis" size="20"/> to <input type="text" name="EndMillis" size="20"/>
<input type="button"
onclick="myfunction('MillisFilter')"
value="Filter"/>
<br />
<br />
Sequence: <input type="text" name="BeginSeq" size="20"/> to <input type="text" name="EndSeq" size="20"/>
<input type="button"
onclick="myfunction(BeginSeq, EndSeq)"
value="Filter"/>
<br />
<br />
<table id="myTable" border="1">
<tr style="background-color:PowderBlue;font-size:70%;">
<th>M</th>
<th>DATE</th>
<th>MILLIS</th>
<th>SEQ</th>
<th>LOGGER</th>
<th>LEVEL</th>
<th>CLASS</th>
<th>METHOD</th>
<th>THREAD</th>
</tr>


<xsl:for-each select="log/record">

<tr style="font-size:70%; font-family:lucida console;">
<script type="text/javascript">
rowID=7
</script>

<td style="color:green; font-size:25px" id="changer" onclick="insRow(rowID)">*</td>

<td><xsl:value-of select="date" /></td>
<td><xsl:value-of select="millis" /></td>
<td><xsl:value-of select="sequence" /></td>
<td><xsl:value-of select="logger" /></td>
<td><xsl:value-of select="level" /></td>
<td><xsl:value-of select="class" /></td>
<td><xsl:value-of select="method" /></td>
<td><xsl:value-of select="thread" /></td>
</tr>

<tr style="font-size:100%; font-family:lucida console;">
<td></td>

<td colspan="8" bgcolor="khaki"><xsl:value-of select="message" /></td>
</tr>

</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

If you apply the two together, you should see cells highlighted in yellow. I want those to be hidden when the page loads. I want it so that the user can click the asterisk on the left and then it shows the highlighted message row for that record. But, I don't know how to manipulate the data to do that.

Is there a way to easily create dynamic IDs for each row? Can I store the message line into a variable and then create a new cell on the row that is clicked on and bring in the text somehow? I'm clueless on the best way to approach this, everything I've tried has failed and i've worked on this for at least 6 hours now. A huge thanks to anyone who can help out or point me in the right direction.
 
Old March 30th, 2009, 07:03 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>Trying to get it to do anything dynamic using XSLT has been very difficult for me

I don't think you have understood the relationship of XSLT, HTML, and Javascript. Your XSLT code executes and generates an HTML page, containing lots of text and markup including perhaps <script> elements. Then it chucks this over the fence to the browser. Once the script is executing, the XSLT processor has done its job and is no longer present at the scene.

Think about the HTML page you want to generate, and then think about the XSLT code to generate it.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old March 30th, 2009, 07:16 PM
Registered User
 
Join Date: Mar 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I didn't mean to put it that way. I am trying to use JavaScript to do the dynamic parts to be a DHTML table.

Can this all be done inside a .xsl file, though? Is there a way use the text retrieved from an XPath statement and store it in a JavaScript variable?
 
Old March 31st, 2009, 03:54 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>Can this all be done inside a .xsl file, though?

You can put all the logic for generating the HTML page in the XSLT file. But that's all it can do. If you want to put a value in a Javascript variable, then you need to generate a Javascript assignment statement within a <script> element, which will be executed once you've finished producing the HTML and handed it over to the browser.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Set xsl variable using Javascript variable Kunn XSLT 5 December 31st, 2008 02:43 AM
DTS Package, XML task. Read XML file and store it Victoria SQL Server DTS 0 July 24th, 2006 02:43 PM
How to store ntext or text value to local variable ramk_1978 SQL Server 2000 3 September 14th, 2005 07:59 PM
How to Store Literal Value in Variable/Parameter kwilliams XSLT 5 August 31st, 2005 08:52 AM
How to store single value in variable? sacred21 Classic ASP Basics 1 December 29th, 2004 05:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.