javaxmlxsltxslt-2.0bxslider

A sequence of more than one item is not allowed as the first argument of fn:substring()


I am getting this error while using substring in xslt, the error message is clear, hence i tried putting the multiple sequence value in variable and using substring for the variable, it doesn't work either, same error. Can someone provide a workaround for this?

Input:

<Path1>
                                    <Path2>SENDER 1</Path2>
                                    <Path2> SENDER xyc</Path2>
                                    <Path2> SENDER </Path2>
                                    <Path2> ORG ID:</Path2>
                                    <Path2> ORG:=</Path2>
                                    <Path2> ORG </Path2>
                                    <Path2> BNF </Path2>
                                    <Path2> BNF NAME:=A</Path2>
                                    <Path2> BNF ADDRESS</Path2>
                                    <Path2> BNF FI ID:=</Path2>
                                    <Path2> BNF FI:=</Path2>
                                    <Path2> REC FI:=</Path2>
                                    <Path2> REC ID:=</Path2>
                                    <Path2> OBI:=</Path2>
                                </Path1>

xslt:

<xsl:element name="EB">

                                            <xsl:element name="ID">
                                                <xsl:value-of select="substring(*:Path1/*:Path2,1,500)"/>
                                            </xsl:element>
                                </xsl:element>

Solution

  • You need to select a single Path2, not a sequence, so either make sure you use a positional predicate e.g. Path2[1] or make sure you use the substring in the context of a single Path2 by e.g. matching on Path2.

    As for your comment, that sounds as if you want e.g. string-join(Path2) => substring(1, 500) in XPath 3.1 or substring(string-join(Path2, ''), 1, 500) in XPath 2.