This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Need Help in working with javascript and XSL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Need Help in working with javascript and XSL" Watch "Need Help in working with javascript and XSL" New topic

Need Help in working with javascript and XSL


Joined: Aug 01, 2001
Posts: 2
I have a couple of questions:
1) How do I use script in XSL to work in the HTML it calls it from?
Below is what I tried to do to test things out but it doesn't work, no alert box appears.
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl=''>
<xsl:template match='/'>
<script language="Javascript"><![CDATA[

2) How can I do script that actually runs in XSL?
I want to creat a series of checkboxes each with the name cb1-cb*, * is the number of records that is filtered.

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl=''>
<xsl:template match='/'>
<xsl:for-each select='data/item[date="27/08/2001"]' order-by='+ time'>
<xsl:element name='input'>
<xsl:attribute name='type'>checkbox</xsl:attribute>
<xsl:attribute name='name'>*****</xsl:attribute>
I have tried doing <xsl:script></xsl:script> but it returns error telling me I can't use xsl:script, I don't understand, I found many examples online using xsl:script. How else can I name my checkboxes in order?

Thanks in Advance!
[This message has been edited by SohJai (edited August 01, 2001).]
Mapraputa Is
Leverager of our synergies

Joined: Aug 26, 2000
Posts: 10065
First, your namespace '' refers to outdated version of MSXML XSLT processor - proprietary Microsoft's version of XSLT. It would be better to use ''
Next, to see alert box appear, you need to include some HTML tags, to have a valid HTML page.
So your whole XSLT will be:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="" version="1.0">
<xsl:template match="/">
<script language="JavaScript"><![CDATA[

2. <xsl:script> isn't a standard XSL element, if I am not mistaken, it' a Microsoft extension. The same about "order-by". All what you need is position() function - it returns a position of the current element in a node-set:
<xsl:template match="/">
<xsl:for-each select='data/item[date="27/08/2001"]'>
<xsl:sort select="time"/>
<input type="checkbox" name="{concat ('cb', position())}"/><br/>

Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
It is sorta covered in the JavaRanch Style Guide.
subject: Need Help in working with javascript and XSL
Similar Threads
xml to xml transform
Confused with Xpath expression! Need Help.
Can Not XSL-Transform Something so Simple.
xsl - need to select on attribute and limit output
XSLT problem.