mhebert
asked on
XSLT 1.0 - <msxsl:script>
In my XSLT 1.0 file, I'm trying to extract a value of a child element for placing it into the HTML <script> tag for initializing a javascript array(see code below). In WD-XSL,the "." or "this" value seems to be a node, and it's working with <xsl:eval>. In XSLT 1.0, can someone tells me what is the value of the "what" parameter in the <msxml:script> getNbOfRules(what) function? I always got errors on this function... What is different here between the old XSL call and the XSLT new one?
========================== ========== ==
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:extra="urn:extra-fun ctions"
xmlns:msxsl="urn:schemas-m icrosoft-c om:xslt">
<xsl:output method="html" doctype-public="-//W3C//DT D HTML 4.0 Transitional//EN"/>
<xsl:template match="/">
<html>
<head><title>Rules</title> </head>
<script language="javascript">
var status = new Array(<xsl:value-of select="extra:getNbOfRules (.)"/>);
</script>
...
</xsl:template>
<msxsl:script implements-prefix="extra" language="javascript">
<![CDATA[
function getNbOfRules(what)
{
var i = 50;
var modules = what.selectSingleNode("MOD ULES/NBOFR ULES");
i = modules.nodeTypedValue;
return i;
}
]]>
</msxsl:script>
</xsl:stylesheet>
==========================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:extra="urn:extra-fun
xmlns:msxsl="urn:schemas-m
<xsl:output method="html" doctype-public="-//W3C//DT
<xsl:template match="/">
<html>
<head><title>Rules</title>
<script language="javascript">
var status = new Array(<xsl:value-of select="extra:getNbOfRules
</script>
...
</xsl:template>
<msxsl:script implements-prefix="extra" language="javascript">
<![CDATA[
function getNbOfRules(what)
{
var i = 50;
var modules = what.selectSingleNode("MOD
i = modules.nodeTypedValue;
return i;
}
]]>
</msxsl:script>
</xsl:stylesheet>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You only ever use msxsl:script if there is no other way.
ASKER
Thanks..I will work on that... ;-)
ASKER
Thanks..I will work on that... ;-)
ASKER
In XSLT, you cannot pass a node in parameter to a <msxsl:script> function? "." isn't a node?
it depends on the context
<xsl:template match="/">
. refers to root and not documentElement
child::node()[1] refers to the documentElement
</xsl:template>
<xsl:template match="/">
. refers to root and not documentElement
child::node()[1] refers to the documentElement
</xsl:template>
ASKER
In this case, where I'm not in the root, and I want to keep a value in a javascript variable(an example, it can be an integer..):
========================== ========== ========
<xsl:for-each select="MODULE">
<xsl:value-of select="extra:setModulePat h(.)"/>
...
</xsl:for-each>
...
<msxsl:script implements-prefix="extra" language="javascript">
<![CDATA[
var modulePath = "";
function setModulePath(node)
{
var filePathNode = node.selectSingleNode("FIL EPATH");
modulePath = filePathNode.nodeTypedValu e + "html\\";
}
...
========================== ========== =======
By what I need to replace the "." in the call to let work properly the javascript function setModulePath()? The "." will be the current <MODULE> node.
==========================
<xsl:for-each select="MODULE">
<xsl:value-of select="extra:setModulePat
...
</xsl:for-each>
...
<msxsl:script implements-prefix="extra" language="javascript">
<![CDATA[
var modulePath = "";
function setModulePath(node)
{
var filePathNode = node.selectSingleNode("FIL
modulePath = filePathNode.nodeTypedValu
}
...
==========================
By what I need to replace the "." in the call to let work properly the javascript function setModulePath()? The "." will be the current <MODULE> node.
please note what I have said earlier.
>>
Thirdly, what is the root (not the same as the documentElement) and because the script is in the CDATA,
you cannot do anything.
WRONG!
>>
<msxsl:script implements-prefix="extra" language="javascript">
<![CDATA[
var modulePath = "";
function setModulePath(node)
{
var filePathNode = node.selectSingleNode("FIL EPATH");
modulePath = filePathNode.nodeTypedValu e + "html\\";
}
<<
RIGHT!
<msxsl:script implements-prefix="extra" language="javascript">
var modulePath = "";
function setModulePath(node)
{
var filePathNode = node.selectSingleNode("FIL EPATH");
modulePath = filePathNode.nodeTypedValu e + "html\\";
}
</msxsl:script>
you place the CDATA around any code which has the reserved XML characters of >,< &
and secondly, this is really not the way you code with XSLT *sigh*, you have to forget about the OLD way.
Next, you MUST return something in your function or it WON'T work, even if you do not intend to use the return value!!!
If you want to hold on to old tricks, you will bang yourself against the wall all the time.
>>
Thirdly, what is the root (not the same as the documentElement) and because the script is in the CDATA,
you cannot do anything.
WRONG!
>>
<msxsl:script implements-prefix="extra" language="javascript">
<![CDATA[
var modulePath = "";
function setModulePath(node)
{
var filePathNode = node.selectSingleNode("FIL
modulePath = filePathNode.nodeTypedValu
}
<<
RIGHT!
<msxsl:script implements-prefix="extra" language="javascript">
var modulePath = "";
function setModulePath(node)
{
var filePathNode = node.selectSingleNode("FIL
modulePath = filePathNode.nodeTypedValu
}
</msxsl:script>
you place the CDATA around any code which has the reserved XML characters of >,< &
and secondly, this is really not the way you code with XSLT *sigh*, you have to forget about the OLD way.
Next, you MUST return something in your function or it WON'T work, even if you do not intend to use the return value!!!
If you want to hold on to old tricks, you will bang yourself against the wall all the time.
I've been reading this post and I'm not sure if I completely follow - so can I call a javascript function in my xsl document or not?
<msxsl:script implements-prefix="extra" language="javascript">
I understand that this line shouldn't be used. But if I have a javascript written in my document, how can I call that function from elsewhere in my document?
<msxsl:script implements-prefix="extra" language="javascript">
I understand that this line shouldn't be used. But if I have a javascript written in my document, how can I call that function from elsewhere in my document?
<xsl:value-of select="name()" />
Secondly, in the process of porting over code from the old style to the new style, you must abandon the method of simple line by line porting! You have to re-engineer the code for XSLT if you have been using less than efficient calls to xsl:script to perform complicate actions.
Thirdly, what is the root (not the same as the documentElement) and because the script is in the CDATA, you cannot do anything.
Fourthly, WHAT (pun intended!) are you intending to do?
Regards,
Brandon Driesen