You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XSLT调用my:UUID4()报XTDE1425错误,求解决方法

解决XSLT调用UUID4()函数时的XTDE1425错误

错误XTDE1425的核心原因是你引用的my:UUID4()函数既没有在当前XSLT代码中定义,也不属于所使用XSLT处理器的内置函数,因此无法被识别。以下是三种可行的解决方案:

方案1:使用XSLT 3.0内置UUID函数(推荐)

如果你的XSLT处理器支持XSLT 3.0(如Saxon HE/PE/EE 9.8及以上版本),可以直接使用标准内置的uuid()函数,无需自定义:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:for-each select="item">
            <item id="{uuid()}">
                <xsl:value-of select="." />
            </item>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

注意:必须在样式表根元素中声明version="3.0",确保处理器启用XSLT 3.0特性。

方案2:依赖处理器扩展函数(XSLT 2.0及以下)

若使用XSLT 2.0或更低版本,可借助处理器的扩展能力生成UUID。以Saxon处理器为例,直接调用Java的java.util.UUID.randomUUID()方法:

  1. 在样式表根元素添加扩展命名空间:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:my="java:java.util.UUID">
  1. 修改调用代码:
<xsl:for-each select="item">
    <item id="{my:randomUUID()}">
        <xsl:value-of select="." />
    </item>
</xsl:for-each>

注意:该方案依赖Java环境,且处理器需支持Java扩展(Saxon系列均支持)。

方案3:纯XSLT实现UUID生成(无扩展依赖)

如果无法使用扩展函数,可通过纯XSLT代码生成符合格式的UUID(随机性略逊于标准UUID,适合应急场景):

  1. 定义生成UUID的模板:
<xsl:template name="generate-uuid">
    <xsl:variable name="hex-chars" select="'0123456789abcdef'" />
    <xsl:variable name="v1" select="concat(
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1)
    )" />
    <xsl:variable name="v2" select="concat(
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1)
    )" />
    <xsl:variable name="v3" select="concat(
        '4',
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1)
    )" />
    <xsl:variable name="v4" select="concat(
        substring('89ab', floor(random()*4)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1)
    )" />
    <xsl:variable name="v5" select="concat(
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1),
        substring($hex-chars, floor(random()*16)+1,1)
    )" />
    <xsl:value-of select="concat($v1, '-', $v2, '-', $v3, '-', $v4, '-', $v5)" />
</xsl:template>
  1. 在循环中调用模板:
<xsl:for-each select="item">
    <item>
        <xsl:attribute name="id">
            <xsl:call-template name="generate-uuid" />
        </xsl:attribute>
        <xsl:value-of select="." />
    </item>
</xsl:for-each>

注意:该方案依赖XSLT的random()函数,不同处理器的随机数实现可能存在差异。

内容的提问来源于stack exchange,提问作者dipanshu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 15:32:24