home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F41596_strSplittoWords2.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2002-02-06  |  2.2 KB  |  66 lines

  1. <xsl:stylesheet version="1.0"
  2. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:xalan="http://xml.apache.org/xalan"
  4. xmlns:str-split2words-func="f:str-split2words-func"
  5. exclude-result-prefixes="xsl xalan str-split2words-func"
  6. >
  7.  
  8.    <xsl:import href="str-foldl.xsl"/>
  9.  
  10.    <!-- to be applied on words.xml -->
  11.  
  12.    <str-split2words-func:str-split2words-func/>
  13.  
  14.    <xsl:output indent="yes" omit-xml-declaration="yes"/>
  15.    
  16.     <xsl:template match="/">
  17.       <xsl:call-template name="str-split-to-words">
  18.         <xsl:with-param name="pStr" select="/*/*"/>
  19.         <xsl:with-param name="pDelimiters" select="',  '"/>
  20.       </xsl:call-template>
  21.     </xsl:template>
  22.  
  23.     <xsl:template name="str-split-to-words">
  24.       <xsl:param name="pStr"/>
  25.       <xsl:param name="pDelimiters"/>
  26.       
  27.       <xsl:variable name="vsplit2wordsFun"
  28.                     select="document('')/*/str-split2words-func:*[1]"/>
  29.                     
  30.       <xsl:variable name="vrtfParams">
  31.        <delimiters><xsl:value-of select="$pDelimiters"/></delimiters>
  32.       </xsl:variable>
  33.  
  34.       <xsl:variable name="vResult">
  35.           <xsl:call-template name="str-foldl">
  36.             <xsl:with-param name="pFunc" select="$vsplit2wordsFun"/>
  37.             <xsl:with-param name="pStr" select="$pStr"/>
  38.             <xsl:with-param name="pA0" select="xalan:nodeset($vrtfParams)"/>
  39.           </xsl:call-template>
  40.       </xsl:variable>
  41.       
  42.       <xsl:copy-of select="xalan:nodeset($vResult)/word"/>
  43.  
  44.     </xsl:template>
  45.  
  46.     <xsl:template match="str-split2words-func:*">
  47.       <xsl:param name="arg1" select="/.."/>
  48.       <xsl:param name="arg2"/>
  49.          
  50.       <xsl:copy-of select="xalan:nodeset($arg1)/*[1]"/>
  51.       <xsl:copy-of select="xalan:nodeset($arg1)/word[position() != last()]"/>
  52.       
  53.       <xsl:choose>
  54.         <xsl:when test="contains($arg1/*[1], $arg2)">
  55.           <xsl:if test="string($arg1/word[last()])">
  56.              <xsl:copy-of select="$arg1/word[last()]"/>
  57.           </xsl:if>
  58.           <word/>
  59.         </xsl:when>
  60.         <xsl:otherwise>
  61.           <word><xsl:value-of select="concat($arg1/word[last()], $arg2)"/></word>
  62.         </xsl:otherwise>
  63.       </xsl:choose>
  64.     </xsl:template>
  65.  
  66. </xsl:stylesheet>