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
Arcanum DevelopmentSubject: Java extension functions, Xalan version in Stylus Studio?
Author: Arcanum Development
Date: 08 Aug 2013 04:24 AM
Java extension functions to be developed for processing NodeList-s.
Primary attempts failed with exceptions, not even possible to retrieve the node type from Java.

Seemingly the objects passed are NodeLists, but Nodes cannot be accessed.

Also failed to use
org.w3c.dom.traversal.NodeIterator

as suggested, the function signature did not meet.

The passed class, indeed, is DTMAxisIterNodeList
which should be NodeList in principle, but functions return exceptions.

Both X14 and X15 behave the same way.


Thanks

A



Java test class:

package test;

import org.w3c.dom.*;
import org.w3c.dom.traversal.NodeIterator;
import org.w3c.dom.DocumentFragment ;
import com.sun.org.apache.xalan.internal.xsltc.DOM;
import com.sun.org.apache.xml.internal.dtm.*;

public class TraverseList
{
static{
System.out.println("hello");
};
public static String traverseList(NodeList nl)
{
String s = "NodeList:";
int l = nl.getLength();
for(int i=0;i<l;i++){
Node n = nl.item(i);
s += n.getNodeName()+":"+n.getNodeType()+";";
}
return s;
}

public static String traverseObject(Object o)
{
String s = o.getClass().getName();
return "ObjectClass:"+s+":";
}







public static String traverse(DocumentFragment df)
{
String s = "DocumentFragment:";
NodeList nl = df.getChildNodes();
int l = nl.getLength();
for(int i=0;i<l;i++){
Node n = nl.item(i);
s += n.getNodeName()+":"+n.getNodeType()+";";
}
return s;

}

}
Investigations pointed out, that node lists derived from the original source document cause no problems.


<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:eplegal="http://www.epo.org/namespaces/ep-legal"
xmlns:traverse="test.TraverseList"
xmlns:exslt="http://exslt.org/common"
xmlns:xalan="http://xml.apache.org/xalan"
extension-element-prefixes="exsl xalan"
>
<xsl:output indent="yes"/>

<xsl:variable name="d" select="document('w:/temp/test.xml')"/>

<xsl:template match="/">
<xsl:variable name="nl" select="/a/*"/>
<xsl:variable name="nld" select="$d/a/*"/>
<test>

<direct><xsl:value-of select="traverse:traverseList(/a/*)"/></direct>
<nodelistdirect><xsl:value-of select="traverse:traverseList($nl)"/></nodelistdirect>
<cnt><xsl:value-of select="count($nld)"/></cnt>

<xsl:variable name="indirect"><xsl:copy-of select="$nl"/></xsl:variable>
<copy><xsl:copy-of select="exslt:node-set($indirect)"/></copy>

<nodelistindirect><xsl:value-of select="traverse:traverseObject(exslt:node-set($indirect))"/></nodelistindirect>
<nodelistfromdoc><xsl:value-of select="traverse:traverseObject($nld)"/></nodelistfromdoc>
<nodelistindirect><xsl:value-of select="traverse:traverseList(exslt:node-set($indirect))"/></nodelistindirect>
<nodelistfromdoc><xsl:value-of select="traverse:traverseList($nld)"/></nodelistfromdoc>

</test>

</xsl:template>

</xsl:stylesheet>


test XML file:

<?xml version="1.0"?>
<a>
<b/><c/><d/>
</a>


Output:

<?xml version='1.0' encoding='UTF-8' ?>
<test xmlns:traverse="test.TraverseList" xmlns:exslt="http://exslt.org/common" xmlns:eplegal="http://www.epo.org/namespaces/ep-legal">
<direct>NodeList:b:1;c:1;d:1;</direct>
<nodelistdirect>NodeList:b:1;c:1;d:1;</nodelistdirect>
<cnt>3</cnt>
<copy>
<b/>
<c/>
<d/>
</copy>
<nodelistindirect>ObjectClass:com.sun.org.apache.xml.internal.dtm.ref.DTMAxisIterNodeList:</nodelistindirect>
<nodelistfromdoc>ObjectClass:com.sun.org.apache.xml.internal.dtm.ref.DTMAxisIterNodeList:</nodelistfromdoc>



Exception dropped for traverse:traverseList(exslt:node-set($indirect)):

java.lang.ArrayIndexOutOfBoundsException: -1
at com.sun.org.apache.xml.internal.utils.SuballocatedIntVector.elementAt(Unknown Source)
at com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2DTM2._exptype(Unknown Source)
at com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase.getNodeType(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl.getNodeName(Unknown Source)
at com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy.getNodeName(Unknown Source)
at test.TraverseList.traverseList(TraverseList.java:20)

Posttop
Ivan PedruzziSubject: Java extension functions, Xalan version in Stylus Studio?
Author: Ivan Pedruzzi
Date: 08 Aug 2013 04:13 PM

This sounds like a Xalan defect, the following calls trigger the error

java:test.TraverseList.traverseList(exslt:node-set($indirect))
java:test.TraverseList.traverseList($nld)

Notice in the stack-trace the error is thrown while accessing the node object

at com.sun.org.apache.xml.internal.utils.SuballocatedIntVector.elementAt(Unknown Source)
at com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2DTM2._exptype(Unknown Source)
at com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase.getNodeType(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl.getNodeName(Unknown Source)
at com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy.getNodeName(Unknown Source)


This works
java:test.TraverseList.traverseList($indirect)

I did few additional experiments using Node but in some cases the processor it's passing a null object

public static String traverseNode(org.w3c.dom.Node n)


Ivan Pedruzzi
Stylus Studio Team

 
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.