xsl-list
[Top] [All Lists]

[xsl] Streamability of rounding effects

2017-06-11 16:40:55
Idle relaxation after XML London. Here is some random text generated using the 
vocabulary of the XSLT 3.0 spec:

<quote>
This  means cases where a parameter to match certain function are copied node 
matches replace all the pattern is no such a valid relative to declarations in 
which is used to the expression. That the right lies the instruction may also 
be. If the same. If no schema for extract the way in the function. The 
functions and result tree. A and others are considered as the context of the p 
element is changed to variables in an adverse effect because both operands as a 
dynamic. Static. Type. Annotation the component of where the functions 
references that a stylesheet then and elements and. CIT is no and then and 
fails to then is any even though this is an output definitions and stylesheets 
that is not a using its sweep of the types defined in an. EQName that has a as 
the and if there are given knowledge of the. An optional as a. In this 
specification defines the rules require implementations are described in static 
error using see. The usage is. Where the node in memory can however share the 
applicable to handle but which the required type is not necessarily. Rule. 
Suppose that facilities also. Streamability of rounding effects.
</quote>

Probably makes about as much sense to the average reader as the original...

Here's the code (try it on a document of your choice...). It builds a data 
structure holding all pairs of adjacent words and then selects the successor of 
each word from these pairs at random.

<xsl:template match="/">
        <xsl:variable name="words" 
                      as="xs:string*" 
                      select="//text()!tokenize(., '\s+')[matches(., 
'^[a-zA-Z]+$')]"/>
        <xsl:variable name="histogram" as="map(*)">
            <xsl:iterate select="tail($words)">
                <xsl:param name="previous" select="head($words)"/>
                <xsl:param name="histogram" select="map{}"/>
                <xsl:on-completion select="$histogram"/>
                <xsl:variable name="new-entry" select="if 
(map:contains($histogram, $previous)) then (map:get($histogram, $previous), .) 
else (.)"/>
                <xsl:next-iteration>
                    <xsl:with-param name="previous" select="."/>
                    <xsl:with-param name="histogram" 
select="map:put($histogram, $previous, $new-entry)"/>
                </xsl:next-iteration>
            </xsl:iterate>
        </xsl:variable>
        <p>
            <xsl:text>This </xsl:text>
            <xsl:iterate select="1 to 200">
                <xsl:param name="word" select="'This'"/>
                <xsl:variable name="options" select="map:get($histogram, 
$word), 'the'"/>
                <xsl:variable name="next" 
select="(random-number-generator(.)?permute($options))[1]"/>
                <xsl:value-of select="(if (matches($next, '^[A-Z]')) then '. ' 
else ' ') || $next"/>
                <xsl:next-iteration>
                    <xsl:with-param name="word" select="$next"/>
                </xsl:next-iteration>
            </xsl:iterate>
            <xsl:text>.</xsl:text>
        </p>
    </xsl:template>
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>
  • [xsl] Streamability of rounding effects, Michael Kay mike(_at_)saxonica(_dot_)com <=