Skip to content

Instantly share code, notes, and snippets.

@martin-honnen
Created July 8, 2023 12:13
Show Gist options
  • Select an option

  • Save martin-honnen/aa36f8f5eba3649daa68c0e9389f8a98 to your computer and use it in GitHub Desktop.

Select an option

Save martin-honnen/aa36f8f5eba3649daa68c0e9389f8a98 to your computer and use it in GitHub Desktop.
XSLT 3.0 sample showing the use of random-number-generator and xsl:iterate to generate a sequence of random numbers
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:param name="count" as="xs:integer" select="25"/>
<xsl:output indent="yes"/>
<xsl:template match="/" name="xsl:initial-template">
<root>
<xsl:iterate select="1 to $count">
<xsl:param name="rng" as="map(*)" select="random-number-generator(current-dateTime())"/>
<number>{$rng?number}</number>
<xsl:next-iteration>
<xsl:with-param name="rng" select="$rng?next()"/>
</xsl:next-iteration>
</xsl:iterate>
<xsl:comment>Run with processor {system-property('xsl:product-name')} {system-property('xsl:product-version')} and file {static-base-uri()} at {current-dateTime()}</xsl:comment>
</root>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment