В контексте XSLT 3, я думаю, один способ получить «новый» random-number-generator
для каждого нужного вам узла - определить аккумулятор:
<xsl:accumulator name="rng" as="map(xs:string, item())" initial-value="random-number-generator(current-dateTime())">
<xsl:accumulator-rule match="foo[@type]" select="$value?next()"/>
</xsl:accumulator>
Таким образом, вы могли бы реализоватьваша функция как
<xsl:function name="gdpr:randomLetter" as="item()*">
<xsl:param name="type" as="xs:string"/>
<xsl:param name="rng" as="map(xs:string, item())"/>
<xsl:choose>
<xsl:when test="$type = 'A'">
<xsl:variable name="randomNumber" select="$rng?permute(1 to 7)[1]"/>
<xsl:variable name="letters" select="('A','O','U','E','I','Y','Q')"/>
<xsl:sequence select="$letters[$randomNumber]"/>
</xsl:when>
<xsl:when test="$type = 'a'">
<xsl:variable name="randomNumber" select="$rng?permute(1 to 7)[1]"/>
<xsl:variable name="letters" select="('a','o','u','e','i','y','q')"/>
<xsl:sequence select="$letters[$randomNumber]"/>
</xsl:when>
<xsl:when test="$type = 'B'">
<xsl:variable name="randomNumber" select="$rng?permute(1 to 19)[1]"/>
<xsl:variable name="letters" select="('W','R','T','P','S','D','F','G','H','J','K','L','M','N','B','V','C','X','Z')"/>
<xsl:sequence select="$letters[$randomNumber]"/>
</xsl:when>
<xsl:when test="$type = 'b'">
<xsl:variable name="randomNumber" select="$rng?permute(1 to 19)[1]"/>
<xsl:variable name="letters" select="('w','r','t','p','s','d','f','g','h','j','k','l','m','n','b','v','c','x','z')"/>
<xsl:sequence select="$letters[$randomNumber]"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="randomNumber" select="$rng?permute(1 to 52)[1]"/>
<xsl:variable name="letters" select="('A','O','U','E','I','Y','Q','a','o','u','e','i','y','q','w','r','t','p','s','d','f','g','h','j','k','l','m','n','b','v','c','x','z','W','R','T','P','S','D','F','G','H','J','K','L','M','N','B','V','C','X','Z')"/>
<xsl:sequence select="$letters[$randomNumber]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
, а затем вызовите ее, например,
<xsl:template match="foo[@type]">
<xsl:copy>
<xsl:value-of select="gdpr:randomLetter(@type, accumulator-before('rng'))"/>
</xsl:copy>
</xsl:template>
и убедитесь, что вы используете
<xsl:mode on-no-match="shallow-copy" use-accumulators="rng"/>