Skip to content
Advertisement

XSLT Error checking type of the expression ‘funcall(tokenize)’

I am trying to get the latest word in a string that is splitted with ‘/’ but for some reason I get the error

Error checking type of the expression 'funcall(tokenize, [variable-ref(effect/node-set), literal-expr(/)])'.

I know that it is only supported in xsl version 2 and I think that I have done so as can be seen in my xsl file

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:xlink="http://www.w3.org/1999/xlink"
 exclude-result-prefixes="xlink"
 >
    <xsl:output method="xml" indent="yes" />
    <xsl:template match="/">
        <Tracks>
            <xsl:apply-templates select="//Tracks"/>
        </Tracks>
    </xsl:template>
    <xsl:template match=
        "//MidiTrack">
        <MidiTrack>
        <xsl:attribute name="id">
            <xsl:value-of select="@Id"/>
        </xsl:attribute>        
        <Effects>
            <xsl:for-each select="descendant::DeviceChain/Devices/*">
                <xsl:variable name="effect" select="descendant::LastPresetRef/descendant::RelativePath/@Value"/>
                <xsl:if test="$effect">
                    <Name>
                        <xsl:value-of select="substring-after($effect, 'Devices/Audio Effects/')"/>
                    </Name>
                </xsl:if>
            </xsl:for-each>
        </Effects>
        </MidiTrack>
    </xsl:template>
    <xsl:template match=
        "//ReturnTrack">
        <ReturnTrack>       
            <xsl:for-each select="descendant::DeviceChain/Devices/*">
                <xsl:variable name="effect" select="descendant::LastPresetRef/descendant::Path/@Value"/>
                <xsl:if test="$effect">
                    <Name>
                        <xsl:value-of select="tokenize($effect, '/')"/>
                    </Name>
                </xsl:if>
            </xsl:for-each>
        </Effects>
        </ReturnTrack>
    </xsl:template>
</xsl:stylesheet>

if I replace the tokenize with substring-after it does not complain about the arguments. A small xml example for the tokenize part

<LastPresetRef>
                                    <Value>
                                        <FilePresetRef Id="1">
                                            <FileRef>
                                                <RelativePathType Value="0" />
                                                <RelativePath Value="" />
                                                <Path Value="/Reverb Default.adv" />
                                                <Type Value="1" />
                                                <LivePackName Value="" />
                                                <LivePackId Value="" />
                                                <OriginalFileSize Value="0" />
                                                <OriginalCrc Value="0" />
                                            </FileRef>
                                        </FilePresetRef>
                                    </Value>
                                </LastPresetRef>

If I run my code WITH the tokenize function in this website http://xslttest.appspot.com/ it works perfectly. Not sure what I am missing here.

Not sure if it is worth noting but I run this template with the help of javax.xml.transform.TransformerFactory

UPDATE:

Ok so I replaced the Transformer to Saxon as mentioned in the comments and it catches the string now but it replaces ‘/’ with ‘ ‘ for some reason. For example if I have aa/bb/cc it returns aa bb cc

Advertisement

Answer

As Martin suggested in the comments, changing the java library to use Saxon HE version 11.4 and using [last()] did the trick

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement