Saturday 6 August 2016

xslt function substring-between()

Issue

Need to return a substring between two strings

Resolution

xslt function

code

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:gm='http://www.griffmonster.org/xslt2/functions' 
version="2.0" exclude-result-prefixes="gm">

<xsl:function name="gm:substring-between">
 <xsl:param name="string"/>
 <xsl:param name="start-string"/>
 <xsl:param name="end-string"/>
 <xsl:sequence select="substring-before(substring-after($string, $start-string),$end-string)"/>
</xsl:function>



</xsl:stylesheet>

Monday 4 January 2016

Determine the position and content of an item in a string sequence

Issue

We have a sequence of strings and for each item we need the position of the item within the sequence

Resolution

use the following xpath expression

Xquery

let
  $items := tokenize('xslt-tricks.blogspot.co.uk/search/label/xquery','/')
return
  for $i in 1 to count($items) 
  return (
   $i, (: position  :)
   $items[$i]  (: item content :)
  )