Hi,
I write a javascript function in xsl (UOMConversion.xsl) as follow: - <?xml version="1.0"?>
-
<xsl:stylesheet version="1.0"
-
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-
-
<script language="Javascript">
-
<![CDATA[
-
var ISOUOM= new Array("KGM","MTR","LTR","CT");
-
var MESUOM= new Array("KG","M","L","KAR");
-
-
function UOMISOTOMES(UOMIn) {
-
var i;
-
var UOMOut;
-
for (i=0; i<=ISOUOM.length; i++)
-
{
-
if (UOMIn == ISOUOM[i]) {
-
UOMOut = MESUOM[i];
-
}
-
}
-
return UOMOut;
-
}
-
]]>
-
</script>
-
</xsl:stylesheet>
I would like to import above UOMConversion.xsl into a xsl (LibUserFunctions.xsl). I write: - <xsl:stylesheet version="1.0"
-
xmlns:xs="http://www.w3.org/2001/XMLSchema"
-
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-
-
<xsl:import href="UOMConversion.xsl"/>
-
....
-
</xsl:stylesheet>
I got an error when I use LibUserFunctions.xsl to transform an xml - "Keyword xsl:stylesheet may not contain script. Error occurred during compilation of included or imported stylesheet 'file..."
Where is the problem?
Regards
maxin
15 8572
I also used date function EXSLT. The date.msxsl.xsl has also some javascript as - <?xml version="1.0"?>
-
<xsl:stylesheet version="1.0"
-
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-
xmlns:date="http://exslt.org/dates-and-times"
-
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
-
extension-element-prefixes="date msxsl">
-
-
<msxsl:script language="Javascript" implements-prefix="date">
-
<![CDATA[
-
...
-
]]>
-
</msxsl:script>
-
</xsl:stylesheet>
The different is I dont have the namespace. I don't have any problem to import date.msxsl.xsl.
Regards
maxin
Hi,
Thanks for you answer.
It seems I need the namespace. I can import the xsl file successfully. However, I still get an error in the above javascript - "Microsoft JScript runtime error Wong number of arguments or invalid property..." I attached some codes.
Here is a xml which will be transformed: -
<?xml version="1.0" encoding="UTF-8" ?>
-
<?xml-stylesheet type="text/xsl" href="LOIPRO01_2_B2MML.xsl"?>
-
<LOIPRO01>
-
<MEINS>MTR</MEINS>
-
</LOIPRO01>
-
The LOIPRO01_2_B2MML.xsl is: -
<?xml version="1.0" encoding="UTF-8"?>
-
<xsl:stylesheet version="1.0"
-
xmlns:xs="http://www.w3.org/2001/XMLSchema"
-
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xmlns="http://www.yyy.com/ad/mes/b2mt-1.0"
-
xmlns:bml="http://www.wbf.org/xml/b2mml-v02"
-
xmlns:LibUserFunctions="http://www.yyy.com/UDF/LibUserFunctions"
-
exclude-result-prefixes="xs xsl xsi LibUserFunctions">
-
-
<xsl:import href="LibUserFunctions.xsl"/>
-
-
<xsl:template match="/LOIPRO01">
-
<bml:UnitOfMeasure>
-
<xsl:call-template name="LibUserFunctions:ISOUOMToMESUOM">
-
<xsl:with-param name="UOM" select="MEINS"/>
-
</xsl:call-template>
-
</bml:UnitOfMeasure>
-
</xsl:template>
-
</xsl:stylesheet>
-
and function ISOUOMToMESUOM is in the imported xsl LibUserFunctions.xsl: -
<?xml version="1.0" encoding="UTF-8"?>
-
<xsl:stylesheet version="1.0"
-
xmlns:xs="http://www.w3.org/2001/XMLSchema"
-
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-
xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date"
-
xmlns:log="http://www.xxx.com"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xmlns:LibUserFunctions="http://www.yyy.com/UDF/LibUserFunctions"
-
exclude-result-prefixes="xs xsl xsi LibUserFunctions">
-
-
<xsl:import href="UOMConversion.xsl"/>
-
-
<xsl:template name="LibUserFunctions:ISOUOMToMESUOM">
-
<xsl:param name="UOM"/>
-
<xsl:value-of select="log:UOMISOTOMES($UOM)"/>
-
</xsl:template>
-
</xsl:stylesheet>
-
the function log:UOMISOTOMES is in the imported UOMConversion.xsl: -
<?xml version="1.0"?>
-
<xsl:stylesheet version="1.0"
-
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-
xmlns:log="http://www.xxx.com"
-
xmlns:msxsl="urn:schemas-microsoft-com:xslt">
-
-
<msxsl:script language="Javascript" implements-prefix="log">
-
<![CDATA[
-
var ISOUOM= new Array("KGM","MTR","LTR","CT");
-
var MESUOM= new Array("KG","M","L","KAR");
-
function UOMISOTOMES(UOMIn) {
-
var i;
-
var UOMOut;
-
for (i=0; i<=ISOUOM.length; i++)
-
{
-
if (UOMIn == ISOUOM[i]) {
-
UOMOut = MESUOM[i];
-
}
-
}
-
return UOMOut;
-
}
-
]]>
-
</msxsl:script>
-
</xsl:stylesheet>
-
Regards
maxin
@maxin
you have a mistake in the for loop. the length of your array is 4, thus the last index is 3. change the end condition to "i < ISOUOM.length".
tip: it is better coding style to compute the array length outside the loop. for larger arrays you get a performance advantage. (this is generally recommended for all programming languages) - l = array.length;
-
for (i=0; i<l; i++) { ... }
Hi Dormilich,
Thanks so much for your answer. I changed my codes, But I stille get the same error. The interesting is if I make the javascript as .js and import it in html. No error occurs.
Regards
maxin
The problem seems in <![CDATA[ ... ]]> of the UOMConversion.xsl. It does not like "==" in if (UOMIn == ISOUOM[i]). However, if I change it to "=", it doesnot work correctly either. Is this a special kind of javascript in CDATA?
Regards
maxin
@maxin
maybe it's time to ask why you put in the JScript this way. to me it seems like an overkill to use xsl where a simple (and working) html call would suffice.
PS: not that I'd always use the most straightforward way.........
It is not a html I will make. This xsl is used to transfer IDOC to B2MML when I import an IDOC from SAP to MES.
just had a quick lookup of IDoc & B2MML. where does the javascript fit in, since both types are xml?
MES will use LOIPRO01_2_B2MML.xsl to transfer IDOC to B2MML, from one xml to another xml. I just nees a function to convert ISO code of UOM (Unit of measure KGM from SAP) to normal UOM (kg in MES) during the transform. However, I can not find a xpath function to do it. Therefor I made a by javascript.
do these units have their own node?
I just need a solution, no matter how to do it. Right now I made it as an array in javascript:
var ISOUOM= new Array("KGM","MTR","LTR","CT");
var MESUOM= new Array("KG","M","L","KAR");
it really depends on how these values are stored in the xml. for instance it is possible to convert them with a <choose> construct. if you use a programming language to do the xsl conversion, you may use its string replace functions to convert the units before (or after) the transformation....
Hi Dormilich,
It is good to discuss my problem with you.
However, the list of UOM can very long, so it is not so good to use <choose>. I could not find not how to use string replace functions? What do you mean?
Regards
Xin
@maxin
that's probably best explained with an example. I use PHP as programming language (because I'm used to it, but it works for every other language too, except that the names & functions differ) - // xml input file
-
$xml_in = "idoc.xml";
-
-
// now do the unit replacement
-
// loading file to a string
-
$xml_in_cont = file_get_contents($xml_in);
-
// replace the unit strings (works with arrays too)
-
$xml_in_conv = str_replace("MTR", "M", $xml_in_cont);
-
-
// loading the xslt processor
-
$proc = new XSLTProcessor;
-
// ... here comes the loading of the required files (left out)
-
$xml_out_cont = $proc->transformToXML();
-
-
// saving file to disc
-
$xml_out = file_put_contents("b2mml.xml", $xml_out_cont);
you use a programm to get the file into string, use the appropriate functions to replace the units, do the xsl transformation, and save the result as file.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Weston C |
last post by:
I know of course that you can use <script src=""></script> in an HTML
document to include javascript code you don't want to spill all over the
page.
I'm wondering if there's a way to include...
|
by: Daniel |
last post by:
I admit that I am a novice when it comes to the HTML DOM and
JavaScript. Basically, here is what I want to do:
1. Import some HTML from a remote web site
2. Parse the HTML to locate a specific...
|
by: Ricardo Garcia |
last post by:
hi, how could i import a js file in another js file???
what i want is the equivalent to:
<script type="text/javascript" src="file.js"></script>
in html
Thanks
|
by: Kevin Newman |
last post by:
I've been toying with a namespace manager, and wanted to get some input.
So what do you think?
if (typeof com == 'undefined') var com = {};
if (!com.unFocus) com.unFocus = {};
...
|
by: anonymous |
last post by:
Hey all, I sent this as a response to someone else's problem, but then I thought it might be useful to more people so I'm starting a new thread to share and discuss it.
I found a great JavaScript...
|
by: VMI |
last post by:
In Access, when a user's going to import a fixed-width format ascii file, a
window in the "Import Text Wizard" lets the user "mark" where in a string
one field will begin and end (with the vertical...
|
by: Joseph Scoccimaro |
last post by:
I am using greasemonkey to create a script that allows one to analyze a
web page. Currently I am trying to import the javascript from an
external file to add to the DOM of a web page. It is...
|
by: Frits v/d Laan |
last post by:
Hi
I cannot figure out how to import an array from PHP into Javascript
MyPHPcode is like this
<?php
$i=0;
While ($i < $num) {
$PHPvar= (" $PHPvar \" $Mystring \" , ");
$i++;
|
by: Praveen |
last post by:
Have a common function in Javascript which do transform for all .xsl's.
XSL object is loaded like this.
var xslobj=new ActiveXObject("MSXML2.FreeThreadedDOMDocument.4.0");
xslobj.async = false;...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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...
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |