home *** CD-ROM | disk | FTP | other *** search
/ MacFormat UK 160 - Disc 2 / MF_UK_160_2.iso / pc / DiscContent / Trials / oxygen / samples / fxsl / testFunc-primes.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2005-07-21  |  1.5 KB  |  53 lines

  1. <xsl:stylesheet version="2.0"
  2.  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3.  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  4.  xmlns:saxon="http://saxon.sf.net/"
  5.  xmlns:f="http://fxsl.sf.net/"
  6.  exclude-result-prefixes="xs saxon f" 
  7.  >
  8.  <xsl:import href="../../frameworks/fxsl/f/func-Primes.xsl"/>
  9.  
  10.  <xsl:output method="text"/>
  11.  
  12. <!--
  13.     Solves the following problem:
  14.     
  15.     Find the first 10-digit prime in consecutive digits of e
  16.     
  17.     See e.g:
  18.     http://www.google.com/googleblog/2004/07/warning-we-brake-for-number-theory.html
  19.  
  20.    Invoke on any xml file.
  21.  
  22.    Expected result: 7427466391
  23. -->
  24.  
  25.  <xsl:variable name="vE" select=
  26.  "concat('2.71828182845904523536',
  27.          '02874713526624977572470',
  28.          '93699959574966967627724',
  29.          '07663035354759457138217',
  30.          '85251664274274663919320',
  31.          '03059921817413596629043',
  32.          '57290033429526059563073',
  33.          '81323286279434907632338',
  34.          '29880753195251019011573',
  35.          '83418793070215408914993',
  36.          '48841675092447614606680',
  37.          '82264800168477411853742',
  38.          '34544243710753907774499',
  39.          '20695517027618'
  40.  )"/>
  41.  
  42.   <xsl:template name="initial" match="/*">
  43.  
  44.     <xsl:variable name="vPortions" 
  45.     select="for $n in 3 to string-length($vE)-9
  46.                     return(substring($vE, $n, 10))
  47.            "/>
  48.  
  49.    <xsl:value-of select="$vPortions[f:isPrime(xs:integer(.))][1]"/>
  50.   </xsl:template>
  51.  
  52. </xsl:stylesheet>
  53.