replaced tabs to spaces
[senf.git] / senfscons / functions.xsl
index f8e22f4..b711cc3 100644 (file)
@@ -7,6 +7,68 @@
   xmlns:exsl="http://exslt.org/common"\r
   extension-element-prefixes="str exsl func">\r
   \r
+<func:function name="str:split">\r
+  <xsl:param name="string" select="''" />\r
+  <xsl:param name="pattern" select="' '" />\r
+  <xsl:choose>\r
+    <xsl:when test="not($string)">\r
+      <func:result select="/.." />\r
+    </xsl:when>\r
+    <xsl:when test="not(function-available('exsl:node-set'))">\r
+      <xsl:message terminate="yes">\r
+        ERROR: EXSLT - Functions implementation of str:split relies on exsl:node-set().\r
+      </xsl:message>\r
+    </xsl:when>\r
+    <xsl:otherwise>\r
+      <xsl:variable name="tokens">\r
+        <xsl:choose>\r
+          <xsl:when test="not($pattern)">\r
+            <xsl:call-template name="str:_split-characters">\r
+              <xsl:with-param name="string" select="$string" />\r
+            </xsl:call-template>\r
+          </xsl:when>\r
+          <xsl:otherwise>\r
+            <xsl:call-template name="str:_split-pattern">\r
+              <xsl:with-param name="string" select="$string" />\r
+              <xsl:with-param name="pattern" select="$pattern" />\r
+            </xsl:call-template>\r
+          </xsl:otherwise>\r
+        </xsl:choose>\r
+      </xsl:variable>\r
+      <func:result select="exsl:node-set($tokens)/token" />\r
+    </xsl:otherwise>\r
+  </xsl:choose>\r
+</func:function>\r
+\r
+<xsl:template name="str:_split-characters">\r
+  <xsl:param name="string" />\r
+  <xsl:if test="$string">\r
+    <token><xsl:value-of select="substring($string, 1, 1)" /></token>\r
+    <xsl:call-template name="str:_split-characters">\r
+      <xsl:with-param name="string" select="substring($string, 2)" />\r
+    </xsl:call-template>\r
+  </xsl:if>\r
+</xsl:template>\r
+\r
+<xsl:template name="str:_split-pattern">\r
+  <xsl:param name="string" />\r
+  <xsl:param name="pattern" />\r
+  <xsl:choose>\r
+    <xsl:when test="contains($string, $pattern)">\r
+      <xsl:if test="not(starts-with($string, $pattern))">\r
+        <token><xsl:value-of select="substring-before($string, $pattern)" /></token>\r
+      </xsl:if>\r
+      <xsl:call-template name="str:_split-pattern">\r
+        <xsl:with-param name="string" select="substring-after($string, $pattern)" />\r
+        <xsl:with-param name="pattern" select="$pattern" />\r
+      </xsl:call-template>\r
+    </xsl:when>\r
+    <xsl:otherwise>\r
+      <token><xsl:value-of select="$string" /></token>\r
+    </xsl:otherwise>\r
+  </xsl:choose>\r
+</xsl:template>\r
+\r
   <!-- ==================================================================== -->\r
   <!-- node-set str:replace(string,object,object)                           -->\r
   <!--                                                                      -->\r