UnitTest( js-in-xslt.asp )

Output

  • (2005) Everyday Italian -- only 90.00U$
  • (2005) Harry Potter -- only 89.97U$
  • (2003) XQuery Kick Start -- only 149.97U$
  • (2003) Learning XML -- only 119.85U$

149.93

Sources

/js-in-xslt.asp

<!--#include virtual="/lib/unit-tests.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en">
    <head>
        <title>Evolved - Unit Test - Javascript in XSLT</title>
        <!--// meta tags //-->
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <!--// link tags //-->
        <link rel="stylesheet" type="text/css" media="screen" href="/lib/unit-tests.css" />
    </head>
    <body>
        <div id="container">
            <div id="container-hd">
                <h1>UnitTest( js-in-xslt.asp )</h1>
            </div>
            <div id="container-bd">
                
<h2>Output</h2>
<div class="code"><pre><%

dim Xml, Xslt

set Xml = Server.createObject("MSXML2.DomDocument.6.0")
set Xslt = Server.createObject("MSXML2.DomDocument.6.0")

Xml.async = false
Xml.load( Server.mapPath("js-in-xslt.xml") )
if( Xml.parseError.errorCode <> 0 ) then
    Response.write( Xml.parseError.reason )
end if

Xslt.async = false
Xslt.setProperty "AllowXsltScript", true
Xslt.load( Server.mapPath("js-in-xslt.xsl") )
if( Xslt.parseError.errorCode <> 0 ) then
    Response.write( Xslt.parseError.reason )
end if

Response.write( Xml.transformNode(Xslt) )

set Xslt = nothing
set Xml = nothing

%></pre></div>
                
            </div>
            <div id="container-ft">
                <h2>Sources</h2>
                <h3><%= Request.ServerVariables("SCRIPT_NAME") %></h3>
                <div class="code"><%= geshify( loadTextFile( Server.mapPath( Request.ServerVariables("SCRIPT_NAME") ) ), "asp" ) %></div>
                <h3>js-in-xslt.xml</h3>
                <div class="code"><%= geshify( loadTextFile( Server.mapPath( "js-in-xslt.xml" ) ), "xml" ) %></div>
                <h3>js-in-xslt.xsl</h3>
                <div class="code"><%= geshify( loadTextFile( Server.mapPath( "js-in-xslt.xsl" ) ), "xml" ) %></div>
            </div>
        </div>
        <!--// javascript tags //-->
    </body>
</html>

js-in-xslt.xml

<bookstore>
    <book category="COOKING">
        <title lang="en">Everyday Italian</title>
        <author>Giada De Laurentiis</author>
        <year>2005</year>
        <price>30.00</price>
    </book>
    <book category="CHILDREN">
        <title lang="en">Harry Potter</title>
        <author>J K. Rowling</author>
        <year>2005</year>
        <price>29.99</price>
    </book>
    <book category="WEB">
        <title lang="en">XQuery Kick Start</title>
        <author>James McGovern</author>
        <author>Per Bothner</author>
        <author>Kurt Cagle</author>
        <author>James Linn</author>
        <author>Vaidyanathan Nagarajan</author>
        <year>2003</year>
        <price>49.99</price>
    </book>
    <book category="WEB">
        <title lang="en">Learning XML</title>
        <author>Erik T. Ray</author>
        <year>2003</year>
        <price>39.95</price>
    </book>
</bookstore>

js-in-xslt.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:js="urn:user-defined-js"
    xmlns:vbs="urn:user-defined-vbs"
>
    
    <xsl:output method="xml"
        omit-xml-declaration="yes"
        encoding="UTF-8"
        indent="yes" />
    
    
    <msxsl:script language="JScript" implements-prefix="js">
<![CDATA[

var sigma_receivable = 0
  , sigma_payable    = 0
;

function addReceivable(value) {
    sigma_receivable += value;
    return value;
}
function addPayable(value) {
    sigma_payable += value;
    return value;
}

function getReceivable() {
    return sigma_receivable;
}

function getPayable() {
    return sigma_payable;
}

function applyMarkup(value, markup) {
    return ( value * ( 1 + ( markup / 100 ) ) ).toFixed(2);
}

]]>
    </msxsl:script>
    <msxsl:script language="VBScript" implements-prefix="vbs">
<![CDATA[

dim sigma_receivable, sigma_payable

sigma_receivable = 0
sigma_payable    = 0

function addReceivable(byVal value)
    sigma_receivable = sigma_receivable + value
    addReceivable = value
end function

function addPayable(value)
    sigma_payable = sigma_payable + value
    addPayable = value
end function

function getReceivable()
    getReceivable = sigma_receivable
end function

function getPayable()
    getPayable = sigma_payable
end function

]]>
    </msxsl:script>

    <xsl:template match="/">
<ul>
<xsl:for-each select="/bookstore/book">
    <li>(<xsl:value-of select="year"/>) <xsl:value-of select="title"/> -- only <xsl:value-of select="js:applyMarkup(number(price), 200)"/>U$</li>
    <xsl:variable name="mothafucka" select="vbs:addPayable(number(price))"/>
</xsl:for-each>
</ul>
<p><xsl:value-of select="vbs:getPayable()"/></p>
    </xsl:template>
    
</xsl:transform>