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
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Scot GreenidgeSubject: Problems using JScript with the built in parser
Author: Scot Greenidge
Date: 22 Jun 2005 10:06 PM
Hello,

I am having problems using the attached embedded JScript function within my XSLT transform. When using either the external MSXML or MSXML 4.0 parsers from within StylusStudio, the script executes without error. When attempting to use either the StylusStudio built in parser or the MSXML .NET parser, I get the following errors:

Built-in Parser:

BabbageM2ToM1.xsl (19, 3)
Object required
Src: Microsoft JScript runtime error
Line:5 Error:0 Scode:800a01a8

Any ideas on why MSXML and MSXML 4.0 consider the script correct and why the built-in parser and/or MSXML .NET fail? I have been unable to determine the root cause.



Here's the embedded JScript function:

<ms:script language="JScript" implements-prefix="usr">
<![CDATA[
function parseSubType(inType) {
var outSubType;
if (typeof(inType) == "object") {
var nodeValue = inType.item(0).childNodes[0].nodeValue;
var tempSubType = new String(nodeValue);
var index = tempSubType.lastIndexOf(".");
outSubType = tempSubType.slice(index+1);
} else {
outSubType="FAILURE-UNSUPPORTED-JSCRIPT-TYPE";
}
return outSubType;
}
]]>
</ms:script>


It is invoked within a template using:

<xsl:attribute name="xsi:type" namespace="http://www.w3.org/2001/XMLSchema-instance">
<xsl:value-of select="usr:parseSubType(@type)"/>
</xsl:attribute>



Thank you,
Scot

Postnext
Ivan PedruzziSubject: Problems using JScript with the built in parser
Author: Ivan Pedruzzi
Date: 23 Jun 2005 09:47 PM
Hi Scot,

I am able to run your script the built-in processor.
With .NET what you are seeing is a runtime error because most likely the script is trying to navigate a DOM node that doesn’t exist.

Are you sure you need a script extension?
Tell us what you are trying to do may be can done with just XSLT.

Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
Scot GreenidgeSubject: Problems using JScript with the built in parser
Author: Scot Greenidge
Date: 24 Jun 2005 11:46 AM
Thank you for the reply Ivan.

I am pretty sure that I am navigating to a valid DOM node but will check this. As I said in my original post both the external MSXML and MSXML 4.0 parsers don't exhibit the same problem given the same data set and XSLT code.

With regard to the question of whether or not the use of an external script is required, I am trying to parse the content of an attribute node that looks something like:

<property name="foo1">
<simple type=Resource.ManagedEntity.ManagedResourceEntity.ServiceDomain>foo1</simple>
</property>

stripping of the most inherited type and using this value as an attribute of a new <xsl:element/>. I.e.

<xsl:attribute name="xsi:type">
<xsl:value-of select=parseSubType(@type)
</xsl:attribute>

I am fairly new to XSLT so there may well be a much better approach to the problem. The use of JScript seemed like the most direct path to gain the additional string parsing capability. I would welcome an alternate approach that just uses XSLT/XPath techniques.

Postnext
Ivan PedruzziSubject: Problems using JScript with the built in parser
Author: Ivan Pedruzzi
Date: 24 Jun 2005 05:03 PM
Scot,

You can definitly solve the problem using XSLT.

Assume to have in input

<?xml version="1.0"?>
<property name="foo1">
<simple type="Resource.ManagedEntity.ManagedResourceEntity.ServiceDomain">foo1</simple>
</property>


Use following XSLT 1.0 transformation

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<xsl:call-template name="lastToken">
<xsl:with-param name="value" select="/property/simple/@type"/>
</xsl:call-template>
</xsl:template>


<xsl:template name="lastToken">
<xsl:param name="value"/>
<xsl:param name="separator" select="'.'"/>
<xsl:choose>
<xsl:when test="substring-after($value, '.')">
<xsl:call-template name="lastToken">
<xsl:with-param name="value" select="substring-after($value, '.')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$value"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>


In XSLT 2.0 is even easier because of the XPath 2.0 function fn:tokenize


<?xml version='1.0'?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/04/xpath-functions">

<xsl:template match="/">
<xsl:value-of select="fn:tokenize(/property/simple/@type, '\.')[position() = last()]"/>
</xsl:template>

</xsl:stylesheet>

Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Posttop
Scot GreenidgeSubject: Problems using JScript with the built in parser
Author: Scot Greenidge
Date: 27 Jun 2005 12:42 PM
Thank you very much for the tutorial Ivan, I appreciate it. Yes, the solution works as you describe. Thank you as well for the pre-notice on the additional support for tokenize in XSLT 2.0.

Best Regards,
Scot

 
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
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.