473,395 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

xslt and javascript

Hi all,
thanks for reading this post .
I have a snippet of xslt code that produces a javascript function .I want to be able to put this code in a file and be able able to make a call to this code from different xsl files .Any idea how I do this .I am using xalan processor .
Thanks for your help .

<xsl:variable name="selects">selects.xml</xsl:variable>

<xsl:variable name="cpe"></xsl:variable>

<script language="JavaScript">
function changeCPEType(n) {
alert(" the index is "+ n);
var myArray = new Array(<xsl:for-each select="document ($selects)">
<xsl:for-each select="//select[@name='model']">
<xsl:for-each select="option">
<xsl:variable name="optionValue" select="."/>

<xsl:choose>
<xsl:when test="$optionValue=''">
"<xsl:value-of select="."/>"
</xsl:when>
<xsl:otherwise>
"<xsl:value-of select="."/>",
</xsl:otherwise>

</xsl:choose>

</xsl:for-each>
</xsl:for-each>
</xsl:for-each>);

alert("value of myArray is "+myArray[n]);
}
</script>
Jul 9 '07 #1
4 1874
Dököll
2,364 Expert 2GB
Hi all,
thanks for reading this post .
I have a snippet of xslt code that produces a javascript function .I want to be able to put this code in a file and be able able to make a call to this code from different xsl files .Any idea how I do this .I am using xalan processor .
Thanks for your help .
[HTML]
<xsl:variable name="selects">selects.xml</xsl:variable>

<xsl:variable name="cpe"></xsl:variable>

<script language="JavaScript">
function changeCPEType(n) {
alert(" the index is "+ n);
var myArray = new Array(<xsl:for-each select="document ($selects)">
<xsl:for-each select="//select[@name='model']">
<xsl:for-each select="option">
<xsl:variable name="optionValue" select="."/>

<xsl:choose>
<xsl:when test="$optionValue=''">
"<xsl:value-of select="."/>"
</xsl:when>
<xsl:otherwise>
"<xsl:value-of select="."/>",
</xsl:otherwise>

</xsl:choose>

</xsl:for-each>
</xsl:for-each>
</xsl:for-each>);

alert("value of myArray is "+myArray[n]);
}
</script>[/HTML]
Thanks for your detailed information, mohallo!

I work with JavaScript but not with XML too much, I use HTML mostly with XML and XSL. If you could tell me what you hope to achieve, or you would like to see an HTML example with XSL and XML, let me know.

I will do some snooping around to see if I can do this with JavaScript, but in the meantime plase set your eyes on these links:

http://www.w3schools.com/xsl/xsl_languages.asp

http://www.w3schools.com/xml/xml_examples.asp

Please stay tuned!
Jul 10 '07 #2
Thanks for your detailed information, mohallo!

I work with JavaScript but not with XML too much, I use HTML mostly with XML and XSL. If you could tell me what you hope to achieve, or you would like to see an HTML example with XSL and XML, let me know.

I will do some snooping around to see if I can do this with JavaScript, but in the meantime plase set your eyes on these links:

http://www.w3schools.com/xsl/xsl_languages.asp

http://www.w3schools.com/xml/xml_examples.asp

Please stay tuned!

Thanks for your reply .
What I am trying to do is instead of including the above code in every xsl file I have I want to include this code in another file .I dont want duplicate code all over the project .I have tried putting this code in another xsl file and using the import and include functions but they dont work .I dont know but I am wondering if the xalan processor I am using is outdated .
I can easily accomplish this with total javascript but want to take this approach .
Thanks for your help
Jul 11 '07 #3
Dököll
2,364 Expert 2GB
Thanks for your reply .
What I am trying to do is instead of including the above code in every xsl file I have I want to include this code in another file .I dont want duplicate code all over the project .I have tried putting this code in another xsl file and using the import and include functions but they dont work .I dont know but I am wondering if the xalan processor I am using is outdated .
I can easily accomplish this with total javascript but want to take this approach .
Thanks for your help
Thanks for replying as well, mohallo...

You have some good ideas here. You probably already checked into your xalan processor but I took a quick look at these Google results and thought you could find helpful: http://www.google.com/search?q=xalan...e7&rlz=1I7SUNA

How do you communicate with your XML files? via HTML/XHTML, I added a response that deals with using XML with HTML here, for XHTML, I'd like to suggest: http://www.w3schools.com/default.asp If you like my approach, you'd be able to make two files with the identical code...
Jul 12 '07 #4
jkmyoung
2,057 Expert 2GB
I'm not sure, but I think what you're asking for is
<xsl:include href="jscript.xsl"/>
http://www.w3schools.com/xsl/el_include.asp
Jul 12 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: RC | last post by:
First, let me say I couldn't find a group discuss XML/XSLT. So I only choose the closest groups to post this message. Here is part of my *.xsl file <xsl:stylesheet...
6
by: Pete Verdon | last post by:
Summary: Can I do an XSLT transform, in the client, of a tree of nodes taken from the displayed page DOM in IE? This works in Firefox. Hi, I'm just starting the process of rewriting part of a...
3
by: RC | last post by:
Let's say: if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { // Now I got an XML object here var xmlDocument = XMLHttpRequestObject.responseXML; // next I have...
4
by: RC | last post by:
Let's say: if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { // Now I got an XML object here var xmlDocument = XMLHttpRequestObject.responseXML; // next I have...
3
by: RC | last post by:
Let's say: if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { // Now I got an XML object here var xmlDocument = XMLHttpRequestObject.responseXML; // next I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.