How to iterate over IDREFS values in XSLT 1.0?

You need to tokenize the value of the idrefsField attribute. XSLT 1.0 has no native tokenize() function, so you need to call a recursive named template to do this for you:

<xsl:template match="node_With_IDREFS_field">
    <xsl:copy>
        <xsl:call-template name="tokenize">
            <xsl:with-param name="text" select="@idrefsField"/>
        </xsl:call-template>
    </xsl:copy>
</xsl:template>

<xsl:template name="tokenize">
    <xsl:param name="text"/>
    <xsl:param name="delimiter" select="' '"/>
    <xsl:variable name="token" select="substring-before(concat($text, $delimiter), $delimiter)" />
        <xsl:if test="$token">
            <newElement ref="{$token}"/>
        </xsl:if>
        <xsl:if test="contains($text, $delimiter)">
            <!-- recursive call -->
            <xsl:call-template name="tokenize">
                <xsl:with-param name="text" select="substring-after($text, $delimiter)"/>
            </xsl:call-template>
        </xsl:if>
</xsl:template>

Alternatively, if your processor supports it, you could use the EXSLT str:tokenize() extension function.

Leave a Comment