XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
joshy joseSubject: How to call user defined java script function in xsl 10
Author: joshy jose
Date: 25 May 2009 01:39 AM
I want to call the following javascript function from an xsl file.

Is it possible to call a javascript function witj XSLT1.0 library?

If it is possible,what is the syntax of calling it?


function MyGetDateTime(Str1)
{
var Strs;
var StrRet;
regExpression = /-|T|:/;

d = new Date(2007,08,22);
Strs = Str1.split(regExpression);

d.setFullYear (Strs[0]);

d.setMonth(Strs[1]-1);
d.setDate(Strs[2]);

d.setHours(Strs[3]);
d.setMinutes(Strs[4]);
d.setSeconds(Strs[5]);

return d.toLocaleString();

}

Thanks ,
Josh

Postnext
John BamptonSubject: How to call user defined java script function in xsl 10
Author: John Bampton
Date: 25 May 2009 12:12 PM
It is possible if you are using XSL with HTML. As for the syntax we would have to see your code to determine that

Posttop
joshy joseSubject: How to call user defined java script function in xsl 10
Author: joshy jose
Date: 26 May 2009 09:05 AM
This is my log.html. It should be opened from IE or Mozilla

////////////////////////////////////////////////////////////////////////////
<html>
<head>
<STYLE>
BODY {margin:0;}
.bg {font:8pt Arial; background-color:white; color:black; }
H1 {font:bold 14pt Arial; width:100%;}
.titleText {font:14pt Arial; padding-left:10px; color:white}
A {color:white}
.row {font:8pt tahoma;}
.header {font:bold 8pt tahoma; cursor:hand;}
.Error {background-color:#ffcccc; color:#000000}
.Warning {background-color:#ffcc99; color:#000000}
.Info {background-color:#FFFFFF; color:#000000}
.Detail {background-color:#ffffff; color:#999999}
</STYLE>

<script>
function loadXMLDoc(fname)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation
&& document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
'Your browser cannot handle this script');
}
xmlDoc.async=false;
xmlDoc.load(fname);
return(xmlDoc);
}

function displayResult()
{

xml=loadXMLDoc("Log.xml");
xsl=loadXMLDoc("Log.xsl");
// code for IE
if (window.ActiveXObject)
{
ex=xml.transformNode(xsl);
document.getElementById("putmehere").innerHTML=ex;
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation
&& document.implementation.createDocument)
{
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml,document);
document.getElementById("putmehere").appendChild(resultDocument);
}

}

</script>
</head>
<body id="putmehere" onload_="displayResult()">
</body>
</html>

/////////////////////////////////////////////////////////////////
Following is the log.xsl
//////////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >

<xsl:template match="/">
<HTML>
<HEAD> </HEAD>
<BODY>
<TABLE width="100%" cellspacing="0" STYLE="background-color:#cc0033">
<TR>
<TD width="100%" align="left" valign="center" class="titleText" style="border-bottom: 3px solid #000000; padding-bottom:8px">
Activity<BR/>
<div class="row">
Version [<xsl:value-of select="//MyLog/VR"/>]
Device name [<xsl:value-of select="//MyLog/CN"/>]
</div>
</TD>
</TR>
<TR>
<TD class="bg" valign="top" colspan="2">
<DIV id="listing"><xsl:apply-templates select ="MyLog" /></DIV>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
</xsl:template>

<xsl:template match="MyLog">
<table STYLE="background-color:white" id="myTable">
<thead>
<tr>
<th align="left" onclick_=""> <DIV class="header"> <u>Date and Time</u></DIV></th>
</tr>
</thead>
<tbody>
<xsl:for-each select="Log">
<xsl:sort select="@time"/>
<TR>
<TD><DIV class="row" STYLE="text-align:left">
<xsl:call-template name="formatDate">
<xsl:with-param name="DateTime" select="@time"></xsl:with-param>
</xsl:call-template></DIV></TD>
</TR>
</xsl:for-each>
</tbody>
</table>
</xsl:template>

<xsl:template name="formatDate">
<xsl:param name="DateTime" />
<xsl:value-of select="$DateTime"/>
</xsl:template>


</xsl:stylesheet>

//////////////////////////////////////////////////////////////////////
This is my log.xml
///////////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="UTF-8"?>
<MyLog>
<CN>Dopod</CN>
<VR>1.0000</VR>
<HASH>601335DAFC924D7B9628</HASH>
<Log component="8192" time="2009-05-20T14:09:33" type="3"> TEST</Log>
<Log component="8192" time="2009-05-20T14:14:33" type="3">TEST</Log>
<Log component="8192" time="2009-05-20T14:18:33" type="3">TEST</Log>
<Log component="2" time="2009-05-20T14:18:33" type="3">TEST</Log>
<Log component="8192" time="2009-05-20T14:18:48" type="3">TEST</Log>
<Log component="8192" time="2009-05-20T14:18:48" type="3">TEST</Log>
<Log component="8192" time="2009-05-20T14:18:48" type="3">TEST</Log>
<Log component="8192" time="2009-05-20T14:18:48" type="3">TEST</Log>

</MyLog>

//////////////////////////////////////////////////////////////////////

My requirement is that how I can fromat the date through a javascript function by passing the 'DateTime' xsl parameter defined in my xsl file

In otherwords how a javascript function like

function MyGetDateTime(Str1)
{
var Strs;
var StrRet;
regExpression = /-|T|:/;

d = new Date(2007,08,22);
Strs = Str1.split(regExpression);

d.setFullYear (Strs[0]);

d.setMonth(Strs[1]-1);
d.setDate(Strs[2]);

d.setHours(Strs[3]);
d.setMinutes(Strs[4]);
d.setSeconds(Strs[5]);

return d.toLocaleString();

}

can be invoked in the place of "$DateTime" of the following statement in an xsl file

<xsl:value-of select="$DateTime"/>

Thanks
josh

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.