Advertisement
Guest User

Untitled

a guest
May 20th, 2010
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 5.03 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3.    xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs xd fn functx"
  4.    xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" version="2.0"
  5.    xmlns:functx="http://www.functx.com"
  6.    xmlns:fn="http://www.w3.org/2006/http://www.stylusstudio.com/xpath.html">
  7.     <xd:doc scope="stylesheet">
  8.         <xd:desc>
  9.             <xd:p><xd:b>Created on:</xd:b> May 19, 2010</xd:p>
  10.             <xd:p><xd:b>Author:</xd:b> alex</xd:p>
  11.             <xd:p></xd:p>
  12.         </xd:desc>
  13.     </xd:doc>
  14.     <xsl:variable name="delimiters">[,.;!?\s"()]+</xsl:variable>
  15.     <xsl:variable name='newline'><xsl:text></xsl:text></xsl:variable>
  16.     <xsl:variable name='search_word'>red</xsl:variable>
  17.     <xsl:variable name='context_number'>2</xsl:variable>
  18.     <xsl:variable name='counter'>1</xsl:variable>
  19.    
  20.  
  21.   <xsl:template name="cazzolo">
  22.       <xsl:param  name="rimaste" as="xs:decimal?"/>
  23.       <xsl:param  name="counter" as="xs:decimal?"/>
  24.       <xsl:param  name="input"/>
  25.       <line>
  26.           <!-- vado a mettere nella variabile la sequenza delle parole tokenizzate -->
  27.           <xsl:variable name='s' select="tokenize($input,'\s')"/>
  28.           <!-- mi ritorna gli indici dove è presente la parola cercata -->
  29.           <xsl:variable name='pos' select="index-of(functx:replace-multi($s,$delimiters,''),$search_word)"/>        
  30.          
  31.           <xsl:choose>
  32.               <!-- stampo tutta la riga -->
  33.               <xsl:when test="count($pos) eq 0">
  34.                   <xsl:value-of select="$s"/>
  35.               </xsl:when>
  36.               <xsl:otherwise>
  37.                   <xsl:for-each select="$s">
  38.                       <xsl:variable name="current_pos" select="position()"/>
  39.                      
  40.                       <!-- parola -->
  41.                       <xsl:for-each select="$pos">
  42.                           <xsl:choose>
  43.                               <xsl:when test="(. - $current_pos) eq 0"><xsl:text disable-output-escaping="yes"><span class="word"></text></xsl:when>
  44.                           </xsl:choose>
  45.                       </xsl:for-each>
  46.                      
  47.                       <!-- inizio contesto -->
  48.                       <xsl:for-each select="$pos">
  49.                           <xsl:choose>
  50.                               <xsl:when test="(. - $current_pos - $context_number) eq 0">INIZIO CONTESTO</xsl:when>
  51.                           </xsl:choose>
  52.                       </xsl:for-each>
  53.                      
  54.                       <xsl:value-of select="."/>
  55.                       <xsl:if test="$current_pos ne count($s)">
  56.                           <xsl:text> </xsl:text>    
  57.                       </xsl:if>
  58.                      
  59.                      
  60.                       <!-- parola -->
  61.                       <xsl:for-each select="$pos">
  62.                           <xsl:choose>
  63.                               <xsl:when test="(. - $current_pos) eq 0"></span></xsl:when>
  64.                           </xsl:choose>
  65.                       </xsl:for-each>
  66.                      
  67.                       <!-- fine contesto -->
  68.                       <xsl:for-each select="$pos">
  69.                           <xsl:choose>
  70.                               <xsl:when test="(. - $current_pos + $context_number) eq 0">FINE CONTESTO</xsl:when>
  71.                           </xsl:choose>
  72.                       </xsl:for-each>
  73.                   </xsl:for-each>
  74.               </xsl:otherwise>
  75.           </xsl:choose>
  76.       </line><xsl:text>
  77.            
  78.       </xsl:text>
  79.      
  80.       <!-- recursive call -->
  81.       <!-- questo if non funziona -->
  82.       <xsl:variable name="provola" select="count(following-sibling::*)"/>
  83.       <xsl:if test="not($counter gt count(following-sibling::*))">
  84.         <xsl:call-template name="cazzolo">
  85.           <xsl:with-param name="rimaste">5</xsl:with-param>
  86.           <xsl:with-param name="counter" select="$counter + 1"/>
  87.           <xsl:with-param name="input" select="self::node()/following-sibling::line[$counter]"></xsl:with-param>
  88.         </xsl:call-template>
  89.       </xsl:if>
  90.      
  91.   </xsl:template>
  92.  
  93.     <xsl:function name="functx:replace-multi" as="xs:string*"
  94.              xmlns:functx="http://www.functx.com" >
  95.   <xsl:param name="arg" as="xs:string*"/>
  96.   <xsl:param name="changeFrom" as="xs:string?"/>
  97.   <xsl:param name="changeTo" as="xs:string?"/>
  98.  
  99.  
  100.   <xsl:for-each select="$arg">
  101.       <xsl:value-of select="replace(., $changeFrom, $changeTo)"/>
  102.   </xsl:for-each>
  103.    
  104. </xsl:function>
  105.    
  106.     <xsl:template match="/">
  107.         <xsl:apply-templates select="//line[1]"/>        
  108.     </xsl:template>
  109.    
  110.    
  111.     <xsl:template match="line">
  112.        
  113.  
  114.  
  115.         <xsl:call-template name="cazzolo">
  116.             <xsl:with-param name="rimaste">5</xsl:with-param>
  117.             <xsl:with-param name="counter" select="$counter"/>
  118.             <xsl:with-param name="input" select="."></xsl:with-param>
  119.         </xsl:call-template>
  120.      
  121.        
  122.  
  123.     </xsl:template>
  124. </xsl:stylesheet>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement