simo Posted September 10, 2007 Share Posted September 10, 2007 hi all my problem : i want to pass value from javascript function to xsl variablehow i can do that ?this is sample of my code ... <script language="javascript"> function test() { var ss=12 return ss } </script> <xsl:for-each select="Date/Days/day"> <xsl:variable name="testday" select="... VALUE OF FUNCTION ... "></xsl:variable> <xsl:if test=".=$testday"> <option value='{$ValueOfDay}'> <xsl:value-of select="." /> </option> </xsl:if> </xsl:for-each>thanx Link to comment Share on other sites More sharing options...
aalbetski Posted September 10, 2007 Share Posted September 10, 2007 It appears that you are trying to embed the script into the XSLT. This is how you would do this using the MSXML parser: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:user="http://www.yourcompanyname.com" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl user" version="1.0"> <xsl:for-each select="Date/Days/day"> <xsl:variable name="testday" select="user:test()"></xsl:variable> <xsl:if test=".=$testday"> <option value='{$ValueOfDay}'> <xsl:value-of select="." /> </option> </xsl:if> </xsl:for-each> <msxsl:script implements-prefix="user" language="JScript"> <![CDATA[ function test() { var ss=12 return ss } ]]> </msxsl:script></xsl:stylesheet> You could also pass the value in as a parameter, separating the XSLT from the script. Link to comment Share on other sites More sharing options...
simo Posted September 11, 2007 Author Share Posted September 11, 2007 thanx for helpi tried to do that but it's not workthe error is : " Namespace : "http://yourcompanyname.com' does not contain any function . "what i can do with this problem Link to comment Share on other sites More sharing options...
boen_robot Posted September 11, 2007 Share Posted September 11, 2007 thanx for helpi tried to do that but it's not workthe error is : " Namespace : "http://yourcompanyname.com' does not contain any function . "what i can do with this problemYou are viewing this in IE, right? As this will not work in other browsers.If so, well... how about you try moving the <msxsl:script/> at the top of the document. This errror may happen because the function is not declared prior to it's usage. Link to comment Share on other sites More sharing options...
simo Posted September 11, 2007 Author Share Posted September 11, 2007 You are viewing this in IE, right? As this will not work in other browsers.in IE and FF not workIf so, well... how about you try moving the <msxsl:script/> at the top of the document. This errror may happen because the function is not declared prior to it's usage.same errorbut when i put "$" <xsl:variable name="testday" select="$user:test()"></xsl:variable>the error change to :Expected token 'eof' found '('.$user:test-->(<--)code:0 Link to comment Share on other sites More sharing options...
aalbetski Posted September 11, 2007 Share Posted September 11, 2007 I had given you enough to answer your question. Sorry. This is now a complete working example that does what you asked. I modified your script as well as dummied up an xml file to process against. XML File Used:<top> <Date> <Days> <day>12</day> </Days> </Date></top>XSLT File:<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:user="http://www.yourcompanyname.com" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl user" version="1.0"> <xsl:template match="*"> <xsl:variable name="ValueOfDay">Tuesday</xsl:variable> <select> <xsl:for-each select="//Date/Days/day"> <xsl:variable name="testday" select="user:test()"></xsl:variable> <xsl:if test=".=$testday"> <option value='{$ValueOfDay}'> <xsl:value-of select="." /> </option> </xsl:if> </xsl:for-each> </select> </xsl:template> <msxsl:script implements-prefix="user" language="JScript"> <![CDATA[ function test() { var ss=12 return ss } ]]> </msxsl:script></xsl:stylesheet>HTML to parse:<script> var m_xmlSource = new ActiveXObject("Msxml2.DOMDocument.4.0") var m_xslStyle = new ActiveXObject("Msxml2.DOMDocument.4.0") m_xmlSource.async = false m_xslStyle.async = false m_xmlSource.load("embed.xml") m_xslStyle.load("embed.xsl") m_xslStyle.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'") document.write(m_xmlSource.transformNode(m_xslStyle))</script> Link to comment Share on other sites More sharing options...
simo Posted September 12, 2007 Author Share Posted September 12, 2007 thank you all; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.