在 apache camel 中,我使用 xslt 创建 xml 请求。我想生成随机 ID 并将其作为 RequestID 作为属性之一传递。有没有办法在 xslt 中生成数字 ID。
<RequestID>12345</RequestID>
很少有条件,比如数字应该只包含数值而不包含字母。最多应为 8 位。
在 apache camel 中,我使用 xslt 创建 xml 请求。我想生成随机 ID 并将其作为 RequestID 作为属性之一传递。有没有办法在 xslt 中生成数字 ID。
<RequestID>12345</RequestID>
很少有条件,比如数字应该只包含数值而不包含字母。最多应为 8 位。
FXSL ( https://github.com/dnovatchev/FXSL-XSLT2 ) 对随机数具有纯 XSLT 2 支持,我正在努力寻找确保 8 位数字的正确方法,但至少
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
expand-text="yes">
<xsl:import href="https://github.com/dnovatchev/FXSL-XSLT2/raw/master/Tests/test-random.xsl"/>
<xsl:variable name="random-number" as="xs:double">
<xsl:call-template name="randomSequence">
<xsl:with-param name="pLength" select="1"/>
<xsl:with-param name="pSeed" select="(current-dateTime() - xs:dateTime('1970-01-01T00:00:00')) div xs:dayTimeDuration('PT1S')"/>
<xsl:with-param name="pStart" select="1"/>
<xsl:with-param name="pEnd" select="100"/>
</xsl:call-template>
</xsl:variable>
<xsl:template match="/">
<RequestID>
<xsl:value-of select="format-number($random-number, '00000001')"/>
</RequestID>
</xsl:template>
</xsl:stylesheet>
在每次调用时给出一个随机数。我相信 Dimitre 稍后会来发布关于如何使用他的库来处理您的案例的更明智的答案。