org/apache/xpath/objects/XObject incompatible with org/apache/xpath/objects/XNodeSet

D

duduch_1er

Hello i tried this code in my stylesheet :

xsl:variable name="items"
select="xsl-usexsl:getElementsBySplitString(.,'i')" />

whith the java function getElementsBySplitString
here the code :

public static Element getElementsBySplitString(String aToSplit, String
aSeparator) throws UseXslException {

// Declaration
int intFound = 0;


// Trace
Log.debug(Constantes.CLE_METIER, mClassName,
"getElementsBySplitString : DEBUT");

try {
Element items= new Element("ITEMS");
if (aToSplit != null) {

intFound = aToSplit.indexOf(aSeparator);

while (intFound != -1) {
Element item = new Element("ITEM",aToSplit.substring(0,
intFound));
items.addContent(item);

aToSplit = aToSplit.substring(intFound + 1);
intFound = aToSplit.indexOf(aSeparator);
}

if (aToSplit.length() > 0){
Element item = new Element("ITEM",aToSplit);
items.addContent(item);

}
}
// Trace
Log.debug(Constantes.CLE_METIER, mClassName,
"getElementsBySplitString : FIN");

return items;


} catch (Exception MyE) {
// Signalisation
Log.erreur(Constantes.CLE_METIER, "split : " + MyE.getMessage());

// Propagation
throw new UseXslException("Impossible de formater une chaine de
caractere en un Node");
}
}

and i get the following error :

org/apache/xpath/objects/XObject incompatible with
org/apache/xpath/objects/XNodeSet

Has someone anyidea for resolve this problem ?
thanks
 
J

Joe Kesselman

org/apache/xpath/objects/XObject incompatible with
org/apache/xpath/objects/XNodeSet

Xalan will recognize objects which implement the DOM's Element interface
as nodes -- but that probably isn't what you're returning (given that
you're using new Element(), which isn't a DOM method.)
 
D

duduch_1er

Joe Kesselman a écrit :
Xalan will recognize objects which implement the DOM's Element interface
as nodes -- but that probably isn't what you're returning (given that
you're using new Element(), which isn't a DOM method.)

Thanks for your answer
I used an other solution for resolving my problem, i use a template
instead of java class

i found the following template :

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
extension-element-prefixes="str">

<xsl:template name="str:split">
<xsl:param name="string" select="''" />
<xsl:param name="pattern" select="' '" />
<xsl:choose>
<xsl:when test="not($string)" />
<xsl:when test="not($pattern)">
<xsl:call-template name="str:_split-characters">
<xsl:with-param name="string" select="$string" />
</xsl:call-template>
</xsl:when>
<xsl:eek:therwise>
<xsl:call-template name="str:_split-pattern">
<xsl:with-param name="string" select="$string" />
<xsl:with-param name="pattern" select="$pattern" />
</xsl:call-template>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

<xsl:template name="str:_split-characters">
<xsl:param name="string" />
<xsl:if test="$string">
<token><xsl:value-of select="substring($string, 1, 1)" /></token>
<xsl:call-template name="str:_split-characters">
<xsl:with-param name="string" select="substring($string, 2)" />
</xsl:call-template>
</xsl:if>
</xsl:template>

<xsl:template name="str:_split-pattern">
<xsl:param name="string" />
<xsl:param name="pattern" />
<xsl:choose>
<xsl:when test="contains($string, $pattern)">
<xsl:if test="not(starts-with($string, $pattern))">
<token><xsl:value-of select="substring-before($string,
$pattern)" /></token>
</xsl:if>
<xsl:call-template name="str:_split-pattern">
<xsl:with-param name="string" select="substring-after($string,
$pattern)" />
<xsl:with-param name="pattern" select="$pattern" />
</xsl:call-template>
</xsl:when>
<xsl:eek:therwise>
<token><xsl:value-of select="$string" /></token>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>

and then you can use it in your xsl stylesheet like this :

first we have a treeResult

<xsl:variable name="rtfSplits">
<xsl:call-template name="split"> <xsl:with-param name="string"
select="string(.)" />
<xsl:with-param name="pattern" select="string(';')" />
</xsl:call-template>
</xsl:variable>

after tranform in nodeset
<xsl:variable name="vSplits" select="xalan:nodeset($rtfSplits)"/>

and after we can parse

<xsl:value-of select="$vSplits/token[1]"/>
<xsl:value-of select="$vSplits/token[2]"/>
<xsl:value-of select="$vSplits/token[3]"/>
 
J

Joseph Kesselman

I used an other solution for resolving my problem, i use a template
instead of java class

That works too. Named templates are often a reasonable substitute for
function calls. XSLT 2.0 makes that easier by adding the ability to
write XSLT code that can be invoked using function-call syntax.
 
J

Joseph Kesselman

(I should have added that one major advantage of doing it all in XSLT is
that your stylesheet is, obviously, more portable this way.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,002
Messages
2,570,261
Members
46,859
Latest member
VallieMcKe

Latest Threads

Top