NJMR
NJMR

Reputation: 1964

Calling a function recursively in XSLT

The below code returns UUID in V4 format i.e 8-4-4-4-12 for a total of 36 characters. I am using https://stackoverflow.com/a/60074845/3747770 to generate the UUID.

<func:function name="Utility:getFormatedV4Uuid">
    <func:result>
        <xsl:text>uuid.</xsl:text>
        <xsl:value-of select="Utility:UUID4()"/>
    </func:result>
</func:function>

But the issue is the function Utility:UUID4 some time returns 35 characters instead of 36 characters and I am unable to reproduce the issue. So I am planning to recursively call the Utility:UUID4 function until it returns 36 characters. How do I recursively call a function Utility:UUID4 until it returns 36 characters in XSLT 1.0? Or, is there anyway to fix the issue?

Upvotes: 0

Views: 74

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117073

As I said in the comments, I don't know how to reproduce the problem.

To answer your question: you could call the calling function recursively until the called function returns a satisfactory result:

<func:function name="Utility:getFormatedV4Uuid">
    <xsl:variable name="uid" select="Utility:UUID4()"/>
    <func:result>
        <xsl:choose>
            <xsl:when test="string-length($uid) = 36">
                <xsl:text>uuid.</xsl:text>
                <xsl:value-of select="$uid"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="Utility:getFormatedV4Uuid()"/>
            </xsl:otherwise>
        </xsl:choose>
    </func:result>
</func:function>

Untested, because I don't know how to test it without being able to reproduce the problem.

Upvotes: 1

Related Questions