xsl:analyze-string with a regex that cannot be statically precomputed
authorMichael Kay <mike@saxonica.com>
Fri, 14 Dec 2018 23:33:54 +0000
changeset 1926 59acff18e7c5
parent 1925 71129363292b
child 1927 5d884354c5d5
xsl:analyze-string with a regex that cannot be statically precomputed
tests/insn/analyze-string/_analyze-string-test-set.xml
tests/insn/analyze-string/analyze-string-005.xsl
--- a/tests/insn/analyze-string/_analyze-string-test-set.xml	Fri Dec 14 23:32:19 2018 +0000
+++ b/tests/insn/analyze-string/_analyze-string-test-set.xml	Fri Dec 14 23:33:54 2018 +0000
@@ -90,7 +90,20 @@
       <source role="." file="analyze-string-905.xml"/>
    </environment>
    
-   
+   <test-case name="analyze-string-005">
+      <description>test xsl:analyze-string with dynamic regex expression.</description>
+      <created by="Michael Kay" on="2018-11-09"/>
+      <environment ref="regex001"/>
+      <dependencies>
+         <spec value="XSLT20+"/>
+      </dependencies>
+      <test>
+         <stylesheet file="analyze-string-005.xsl"/>
+      </test>
+      <result>
+         <assert-xml><![CDATA[<out>|Mary had a littl[e] lamb|Its fl[e][e]c[e] was black as soot|And [e]v[e]rywh[e]r[e] that Mary w[e]nt|It put its sooty foot|</out>]]></assert-xml>
+      </result>
+   </test-case>
 
    <test-case name="analyze-string-006">
       <description>test xsl:analyze-string.</description>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/insn/analyze-string/analyze-string-005.xsl	Fri Dec 14 23:33:54 2018 +0000
@@ -0,0 +1,22 @@
+<?xml version="1.0"?> 
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
+
+  <?spec xslt#analyze-string?>
+  <!-- PURPOSE: test xsl:analyze-string with dynamic regex expression. -->
+  
+  <xsl:param name="re" select="'e'"/>
+  
+  <xsl:template match="/">
+    <out>
+      <xsl:variable name="v">
+        <xsl:analyze-string select="doc" regex="{$re}">
+         <xsl:matching-substring>[<xsl:value-of select="."/>]</xsl:matching-substring>
+         <xsl:non-matching-substring><xsl:value-of select="."/></xsl:non-matching-substring>
+        </xsl:analyze-string>
+      </xsl:variable>
+      <xsl:value-of select="translate($v, '&#xa;', '|')"/>
+    </out>
+  </xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file