XSL – Adams Bros Blog http://blog.adamsbros.org Sat, 14 Nov 2015 22:00:12 +0000 en-US hourly 1 https://wordpress.org/?v=5.2.2 XSL Break or Wrap String on Word Boundary http://blog.adamsbros.org/2009/11/22/xsl-break-string-on-word-boundary/ http://blog.adamsbros.org/2009/11/22/xsl-break-string-on-word-boundary/#comments Sun, 22 Nov 2009 23:00:16 +0000 http://blog.adamsbros.org/?p=93 I’ve searched all over the Internet for this, and was unable to find anything reasonable.  I found an example somewhere, of how to break a string at a specific location, but it breaks whether there is a word there or not.  So, either you have to re-compose the XML elements without a space, and hope every system you interact with does the same thing as you,  or re-compose them with a space, and a word may then be broken up in the end result.

In my example below, I break a string on a word boundary, outputting to an XML element called “NoteMessage” from the PESC standard.  This is dependant on Java, but you could use any language that has a useful lastIndexOf function.  In the case of Java, with zero based string index, we need to compensate for the one based string index that XSL has.  So, we add one to the result of the lastIndexOf() call.



  
  
  

  
    
      
    
  

  
    
    
      
        
        
        
      
      
        
        
        
        
          
        
        
          
        
      
    
  
]]>
http://blog.adamsbros.org/2009/11/22/xsl-break-string-on-word-boundary/feed/ 4