apache-camel - apache camel:在 xslt 中生成随机数字 ID
问题描述
在 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 稍后会来发布关于如何使用他的库来处理您的案例的更明智的答案。
推荐阅读
- activemq - 无法更改 ActiveMQ redeliveryPolicy
- python - Azure机器学习python无法打开文件
- macos - 即使具有完全访问权限,终端仍显示“不允许操作”
- powershell - Powershell 比较对象为每个 SideIndicator 输出单独的文件
- wordpress - 在 WordPress 中,贡献者是否可以在编辑或管理员批准后更改为发布应用?
- android - Windows 上的反斜杠问题和 React Native run-android 命令
- java - 转录以仅使用 stream()
- docker - 如何清除 docker build 缓存(一直说 0B 已回收)
- java - 某些设备在尝试播放 Android Mediaplayer 时报告 java.lang.IllegalStateException
- r - 创建一个包含 (9 ) 个数据框的列表