0

I've a XSLT code like below with a simple comma seperated variable. But what I would like is to split that based on the comma and put every value in a for-each loop. I was trying it by using substring-before that don't work, I get a runtime error. Is this possible to do in XSLT 1.0 and what is the best way to do that?

Update: The variable is already inside my XSLT code and it is not coming from an external XML file.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:variable name="SortOrder">Birthday, Housenumber, Zipcode, Carbrand, LicensePlate, Polis, Damageyears, Kmperyear</xsl:variable>
        <xsl:variable name="delimeter">, </xsl:variable>
        <xsl:for-each select="substring-before(SortOrder,delimeter)">
            do something<br/>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>
  • Which XSLT 1.0 processor exactly do you use, does it have support for EXSLT's tokenize or split? – Martin Honnen Jan 09 '22 at 11:56
  • There is no native split function in XSLT 1.0. You need to use recursion or an XSLT extension function to split strings, see duplicate thread. – Tomalak Jan 09 '22 at 11:56
  • @MartinHonnen I'm not sure, but I think it is split. Is there a way how I can check that? – Ronald Vesterink Jan 09 '22 at 11:57
  • @Tomalak, I don't think it's a duplicate of my question. I want to split a variable that is already in my XSLT and not from a external XML file. – Ronald Vesterink Jan 09 '22 at 12:01
  • 1
    @RonaldVesterink You want to split a string. How that string came into your XSLT is not relevant. – Tomalak Jan 09 '22 at 12:03
  • 1
    @RonaldVesterink See here how to identify your processor: https://stackoverflow.com/a/25245033/3016153 -- P.S. If the string is hard-coded in your XSLT then it' could just as well be hard-coded in an already split form. – michael.hor257k Jan 09 '22 at 13:32

0 Answers0