Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs xd fn functx"
- xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" version="2.0"
- xmlns:functx="http://www.functx.com"
- xmlns:fn="http://www.w3.org/2006/http://www.stylusstudio.com/xpath.html">
- <xd:doc scope="stylesheet">
- <xd:desc>
- <xd:p><xd:b>Created on:</xd:b> May 19, 2010</xd:p>
- <xd:p><xd:b>Author:</xd:b> alex</xd:p>
- <xd:p></xd:p>
- </xd:desc>
- </xd:doc>
- <xsl:variable name="delimiters">[,.;!?\s"()]+</xsl:variable>
- <xsl:variable name='newline'><xsl:text></xsl:text></xsl:variable>
- <xsl:variable name='search_word'>red</xsl:variable>
- <xsl:variable name='context_number'>2</xsl:variable>
- <xsl:variable name='counter'>1</xsl:variable>
- <xsl:template name="cazzolo">
- <xsl:param name="rimaste" as="xs:decimal?"/>
- <xsl:param name="counter" as="xs:decimal?"/>
- <xsl:param name="input"/>
- <line>
- <!-- vado a mettere nella variabile la sequenza delle parole tokenizzate -->
- <xsl:variable name='s' select="tokenize($input,'\s')"/>
- <!-- mi ritorna gli indici dove è presente la parola cercata -->
- <xsl:variable name='pos' select="index-of(functx:replace-multi($s,$delimiters,''),$search_word)"/>
- <xsl:choose>
- <!-- stampo tutta la riga -->
- <xsl:when test="count($pos) eq 0">
- <xsl:value-of select="$s"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:for-each select="$s">
- <xsl:variable name="current_pos" select="position()"/>
- <!-- parola -->
- <xsl:for-each select="$pos">
- <xsl:choose>
- <xsl:when test="(. - $current_pos) eq 0"><xsl:text disable-output-escaping="yes"><span class="word"></text></xsl:when>
- </xsl:choose>
- </xsl:for-each>
- <!-- inizio contesto -->
- <xsl:for-each select="$pos">
- <xsl:choose>
- <xsl:when test="(. - $current_pos - $context_number) eq 0">INIZIO CONTESTO</xsl:when>
- </xsl:choose>
- </xsl:for-each>
- <xsl:value-of select="."/>
- <xsl:if test="$current_pos ne count($s)">
- <xsl:text> </xsl:text>
- </xsl:if>
- <!-- parola -->
- <xsl:for-each select="$pos">
- <xsl:choose>
- <xsl:when test="(. - $current_pos) eq 0"></span></xsl:when>
- </xsl:choose>
- </xsl:for-each>
- <!-- fine contesto -->
- <xsl:for-each select="$pos">
- <xsl:choose>
- <xsl:when test="(. - $current_pos + $context_number) eq 0">FINE CONTESTO</xsl:when>
- </xsl:choose>
- </xsl:for-each>
- </xsl:for-each>
- </xsl:otherwise>
- </xsl:choose>
- </line><xsl:text>
- </xsl:text>
- <!-- recursive call -->
- <!-- questo if non funziona -->
- <xsl:variable name="provola" select="count(following-sibling::*)"/>
- <xsl:if test="not($counter gt count(following-sibling::*))">
- <xsl:call-template name="cazzolo">
- <xsl:with-param name="rimaste">5</xsl:with-param>
- <xsl:with-param name="counter" select="$counter + 1"/>
- <xsl:with-param name="input" select="self::node()/following-sibling::line[$counter]"></xsl:with-param>
- </xsl:call-template>
- </xsl:if>
- </xsl:template>
- <xsl:function name="functx:replace-multi" as="xs:string*"
- xmlns:functx="http://www.functx.com" >
- <xsl:param name="arg" as="xs:string*"/>
- <xsl:param name="changeFrom" as="xs:string?"/>
- <xsl:param name="changeTo" as="xs:string?"/>
- <xsl:for-each select="$arg">
- <xsl:value-of select="replace(., $changeFrom, $changeTo)"/>
- </xsl:for-each>
- </xsl:function>
- <xsl:template match="/">
- <xsl:apply-templates select="//line[1]"/>
- </xsl:template>
- <xsl:template match="line">
- <xsl:call-template name="cazzolo">
- <xsl:with-param name="rimaste">5</xsl:with-param>
- <xsl:with-param name="counter" select="$counter"/>
- <xsl:with-param name="input" select="."></xsl:with-param>
- </xsl:call-template>
- </xsl:template>
- </xsl:stylesheet>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement