Random

Attributes

URI:http://www.xml.org/pipe/xpe/filter/random
Type:filter
Namespace:http://www.xml.org/pipe/xpe
Owner:http://www.xmlpipe.org/xpe

Description

This filter generates random values. The filter reacts to the following XML fragment:


   <t:random  type="{int,double,gaussian,boolean}"  xmlns:t="http://www.xml.org/pipe/xpe" />

The entire element is replaced by a unique random value by the filter.

Example usage

The following example illustrates how the Random filter could be used within an XPE pipeline definition (xpipedef.xml) file:


   <xpipeDef  xmlns="http://www.xml.org/xml/pipe" >
      <register  uri="xslt/randomgen" >
         <xslt  href="ROOT/test/xslt/randomgen.xsl" />
      </register>
      <register  uri="random" >
         <xpipe>
            <xnode  type="http://www.xml.org/pipe/xpe/source/http" />
            <xnode  type="xslt/randomgen" />
            <xnode  type="http://www.xml.org/pipe/xpe/filter/random" />
            <xsink  type="http://www.xml.org/pipe/xpe/sink/http" >
               <property  name="method"  value="xml" />
            </xsink>
         </xpipe>
      </register>
   </xpipeDef>

If randomgen.xsl contains the following:


   <xsl:stylesheet  version="2.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
      <xsl:import  href="copy.xsl" />
      <xsl:output  method="xml" />
      <xsl:template  match="http:httpRequest" >
         <result  xmlns="" >
            <randomInt>
               <t:random  type="int"  xmlns:t="http://www.xml.org/pipe/xpe" />
            </randomInt>
            <randomDouble>
               <t:random  type="double"  xmlns:t="http://www.xml.org/pipe/xpe" />
            </randomDouble>
            <randomGaussian>
               <t:random  type="gaussian"  xmlns:t="http://www.xml.org/pipe/xpe" />
            </randomGaussian>
            <randomBoolean>
               <t:random  type="boolean"  xmlns:t="http://www.xml.org/pipe/xpe" />
            </randomBoolean>
         </result>
      </xsl:template>
   </xsl:stylesheet>

Then executing the pipeline (via a HTTP GET) will produce XML similar to:


   <result  xmlns="" >
      <randomInt>
         8
      </randomInt>
      <randomDouble>
         0.10665924677915783
      </randomDouble>
      <randomGaussian>
         0.6184980169710917
      </randomGaussian>
      <randomBoolean>
         false
      </randomBoolean>
   </result>