You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mu...@apache.org on 2023/07/08 16:19:03 UTC
[xalan-java] branch xalan-j_xslt3.0 updated: improving little bit implementation of xpath 3.1 'if' conditional expression. improving dereferencing xslt 3.0 variable when it refers to a context item from an xpath 3.1 sequence with atomic values. adding few new related working test cases as well.
This is an automated email from the ASF dual-hosted git repository.
mukulg pushed a commit to branch xalan-j_xslt3.0
in repository https://gitbox.apache.org/repos/asf/xalan-java.git
The following commit(s) were added to refs/heads/xalan-j_xslt3.0 by this push:
new 62091b84 improving little bit implementation of xpath 3.1 'if' conditional expression. improving dereferencing xslt 3.0 variable when it refers to a context item from an xpath 3.1 sequence with atomic values. adding few new related working test cases as well.
new b0d57769 Merge pull request #22 from mukulga/xalan-j_xslt3.0_mukul
62091b84 is described below
commit 62091b8438c4737499fbbd772e3331f4ba0f2604
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Sat Jul 8 21:43:16 2023 +0530
improving little bit implementation of xpath 3.1 'if' conditional expression. improving dereferencing xslt 3.0 variable when it refers to a context item from an xpath 3.1 sequence with atomic values. adding few new related working test cases as well.
---
src/org/apache/xalan/templates/ElemVariable.java | 7 ++++
src/org/apache/xpath/composite/IfExpr.java | 12 +++++--
tests/fn_unparsed_text/gold/test5.out | 11 +++++++
tests/fn_unparsed_text/srch_file.txt | 1 +
tests/fn_unparsed_text/test1_a.xml | 11 +++++++
.../test3.xsl => fn_unparsed_text/test5.xsl} | 34 +++++++++----------
tests/if_expr/gold/test7.out | 15 +++++++++
tests/if_expr/gold/test8.out | 11 +++++++
tests/if_expr/srch_file.txt | 1 +
tests/if_expr/test1_f.xml | 11 +++++++
tests/if_expr/test3.xsl | 2 +-
tests/if_expr/{test3.xsl => test6.xsl} | 31 ++++++++++--------
tests/if_expr/{test3.xsl => test7.xsl} | 38 ++++++++++++----------
.../apache/xalan/xpath3/FnUnparsedTextTests.java | 10 ++++++
tests/org/apache/xalan/xpath3/IfExprTests.java | 20 ++++++++++++
15 files changed, 161 insertions(+), 54 deletions(-)
diff --git a/src/org/apache/xalan/templates/ElemVariable.java b/src/org/apache/xalan/templates/ElemVariable.java
index ba3d236f..2505408c 100644
--- a/src/org/apache/xalan/templates/ElemVariable.java
+++ b/src/org/apache/xalan/templates/ElemVariable.java
@@ -25,6 +25,7 @@ import org.apache.xml.utils.QName;
import org.apache.xpath.Expression;
import org.apache.xpath.XPath;
import org.apache.xpath.XPathContext;
+import org.apache.xpath.axes.SelfIteratorNoPredicate;
import org.apache.xpath.functions.FuncExtFunction;
import org.apache.xpath.functions.Function;
import org.apache.xpath.objects.ResultSequence;
@@ -317,6 +318,12 @@ public class ElemVariable extends ElemTemplateElement
return evalResult;
}
+ else if (selectExpression instanceof SelfIteratorNoPredicate) {
+ XObject xpath3ContextItem = xctxt.getXPath3ContextItem();
+ if (xpath3ContextItem != null) {
+ return xpath3ContextItem;
+ }
+ }
if (var == null) {
var = m_selectPattern.execute(xctxt, sourceNode, this);
diff --git a/src/org/apache/xpath/composite/IfExpr.java b/src/org/apache/xpath/composite/IfExpr.java
index e5364d94..8fa4a6f0 100644
--- a/src/org/apache/xpath/composite/IfExpr.java
+++ b/src/org/apache/xpath/composite/IfExpr.java
@@ -108,19 +108,25 @@ public class IfExpr extends Expression {
XPath conditionlExprXpath = new XPath(conditionalExprXPathStr, srcLocator, null,
XPath.SELECT, null);
- conditionlExprXpath.fixupVariables(fVars, fGlobalsSize);
+ if (fVars != null) {
+ conditionlExprXpath.fixupVariables(fVars, fGlobalsSize);
+ }
XObject conditionalXpathExprResult = conditionlExprXpath.execute(xctxt, contextNode, null);
if (conditionalXpathExprResult.bool()) {
XPath thenExprXpath = new XPath(thenExprXPathStr, srcLocator, null, XPath.SELECT, null);
- thenExprXpath.fixupVariables(fVars, fGlobalsSize);
+ if (fVars != null) {
+ thenExprXpath.fixupVariables(fVars, fGlobalsSize);
+ }
evalResult = thenExprXpath.execute(xctxt, contextNode, null);
}
else {
XPath elseExprXpath = new XPath(elseExprXPathStr, srcLocator, null, XPath.SELECT, null);
- elseExprXpath.fixupVariables(fVars, fGlobalsSize);
+ if (fVars != null) {
+ elseExprXpath.fixupVariables(fVars, fGlobalsSize);
+ }
evalResult = elseExprXpath.execute(xctxt, contextNode, null);
}
diff --git a/tests/fn_unparsed_text/gold/test5.out b/tests/fn_unparsed_text/gold/test5.out
new file mode 100644
index 00000000..9c166de8
--- /dev/null
+++ b/tests/fn_unparsed_text/gold/test5.out
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?><srchResult>
+ <word>hello</word>
+ <word>world</word>
+ <word>xml</word>
+</srchResult><srchResult>
+ <word>this</word>
+ <word>is</word>
+</srchResult><srchResult>
+ <word>xml</word>
+ <word>document</word>
+</srchResult>
diff --git a/tests/fn_unparsed_text/srch_file.txt b/tests/fn_unparsed_text/srch_file.txt
new file mode 100644
index 00000000..1c29fb50
--- /dev/null
+++ b/tests/fn_unparsed_text/srch_file.txt
@@ -0,0 +1 @@
+l,is,m
\ No newline at end of file
diff --git a/tests/fn_unparsed_text/test1_a.xml b/tests/fn_unparsed_text/test1_a.xml
new file mode 100644
index 00000000..0a20ac8e
--- /dev/null
+++ b/tests/fn_unparsed_text/test1_a.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<list>
+ <word>hello</word>
+ <word>world</word>
+ <word>this</word>
+ <word>is</word>
+ <word>test</word>
+ <word>xml</word>
+ <word>document</word>
+</list>
+
\ No newline at end of file
diff --git a/tests/if_expr/test3.xsl b/tests/fn_unparsed_text/test5.xsl
similarity index 57%
copy from tests/if_expr/test3.xsl
copy to tests/fn_unparsed_text/test5.xsl
index ec49a577..e917cade 100644
--- a/tests/if_expr/test3.xsl
+++ b/tests/fn_unparsed_text/test5.xsl
@@ -4,28 +4,26 @@
<!-- Author: mukulg@apache.org -->
- <!-- use with test1_c.xml -->
+ <!-- use with test1_a.xml -->
- <!-- An XSLT stylesheet, to test the XPath 3.1 "if" conditional
- expression, when used within xsl:for-each-group to transform
- the current-grouping-key() value. -->
+ <!-- Test case description : This XSLT stylesheet, searches an XML input
+ document's contents, for the keywords mentioned within an auxiliary
+ text file srch_file.txt and produces the search results as output
+ of XSLT transformation. -->
<xsl:output method="xml" indent="yes"/>
- <xsl:variable name="gThan" select="function($x, $y) { $x gt $y }"/>
-
- <xsl:template match="/elem">
- <result>
- <xsl:for-each-group select="item" group-by="$gThan(a, b)">
- <xsl:variable name="grtOrLess" select="if (string(current-grouping-key()) eq 'true')
- then 'greater'
- else 'lessOrEqual'"/>
- <xsl:element name="{normalize-space($grtOrLess)}">
- <xsl:attribute name="count" select="count(current-group())"/>
- <xsl:copy-of select="current-group()"/>
- </xsl:element>
- </xsl:for-each-group>
- </result>
+ <xsl:variable name="scfFileContents" select="unparsed-text('srch_file.txt')"/>
+
+ <xsl:template match="/">
+ <xsl:variable name="srchInp" select="/list/word"/>
+ <xsl:variable name="srchKeyWords" select="tokenize($scfFileContents, ',')"/>
+ <xsl:for-each select="$srchKeyWords">
+ <xsl:variable name="keyWord" select="."/>
+ <srchResult>
+ <xsl:copy-of select="$srchInp[contains(., $keyWord)]"/>
+ </srchResult>
+ </xsl:for-each>
</xsl:template>
<!--
diff --git a/tests/if_expr/gold/test7.out b/tests/if_expr/gold/test7.out
new file mode 100644
index 00000000..4880d129
--- /dev/null
+++ b/tests/if_expr/gold/test7.out
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <one>
+ <word>hello</word>
+ <word>world</word>
+ <word>xml</word>
+ </one>
+ <two>
+ <word>this</word>
+ <word>is</word>
+ </two>
+ <three>
+ <word>xml</word>
+ <word>document</word>
+ </three>
+</result>
diff --git a/tests/if_expr/gold/test8.out b/tests/if_expr/gold/test8.out
new file mode 100644
index 00000000..9c166de8
--- /dev/null
+++ b/tests/if_expr/gold/test8.out
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?><srchResult>
+ <word>hello</word>
+ <word>world</word>
+ <word>xml</word>
+</srchResult><srchResult>
+ <word>this</word>
+ <word>is</word>
+</srchResult><srchResult>
+ <word>xml</word>
+ <word>document</word>
+</srchResult>
diff --git a/tests/if_expr/srch_file.txt b/tests/if_expr/srch_file.txt
new file mode 100644
index 00000000..1c29fb50
--- /dev/null
+++ b/tests/if_expr/srch_file.txt
@@ -0,0 +1 @@
+l,is,m
\ No newline at end of file
diff --git a/tests/if_expr/test1_f.xml b/tests/if_expr/test1_f.xml
new file mode 100644
index 00000000..0a20ac8e
--- /dev/null
+++ b/tests/if_expr/test1_f.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<list>
+ <word>hello</word>
+ <word>world</word>
+ <word>this</word>
+ <word>is</word>
+ <word>test</word>
+ <word>xml</word>
+ <word>document</word>
+</list>
+
\ No newline at end of file
diff --git a/tests/if_expr/test3.xsl b/tests/if_expr/test3.xsl
index ec49a577..80751642 100644
--- a/tests/if_expr/test3.xsl
+++ b/tests/if_expr/test3.xsl
@@ -20,7 +20,7 @@
<xsl:variable name="grtOrLess" select="if (string(current-grouping-key()) eq 'true')
then 'greater'
else 'lessOrEqual'"/>
- <xsl:element name="{normalize-space($grtOrLess)}">
+ <xsl:element name="{$grtOrLess}">
<xsl:attribute name="count" select="count(current-group())"/>
<xsl:copy-of select="current-group()"/>
</xsl:element>
diff --git a/tests/if_expr/test3.xsl b/tests/if_expr/test6.xsl
similarity index 64%
copy from tests/if_expr/test3.xsl
copy to tests/if_expr/test6.xsl
index ec49a577..6d55b708 100644
--- a/tests/if_expr/test3.xsl
+++ b/tests/if_expr/test6.xsl
@@ -4,27 +4,30 @@
<!-- Author: mukulg@apache.org -->
- <!-- use with test1_c.xml -->
+ <!-- use with test1_f.xml -->
<!-- An XSLT stylesheet, to test the XPath 3.1 "if" conditional
- expression, when used within xsl:for-each-group to transform
- the current-grouping-key() value. -->
+ expression. The XPath "if" conditional expression example
+ illustrated within this stylesheet test, is written within
+ body of an XPath function item expression. -->
<xsl:output method="xml" indent="yes"/>
- <xsl:variable name="gThan" select="function($x, $y) { $x gt $y }"/>
+ <xsl:variable name="filterCheck" select="function($str, $srch) { if (contains($str, $srch))
+ then true()
+ else false() }"/>
- <xsl:template match="/elem">
+ <xsl:template match="/list">
<result>
- <xsl:for-each-group select="item" group-by="$gThan(a, b)">
- <xsl:variable name="grtOrLess" select="if (string(current-grouping-key()) eq 'true')
- then 'greater'
- else 'lessOrEqual'"/>
- <xsl:element name="{normalize-space($grtOrLess)}">
- <xsl:attribute name="count" select="count(current-group())"/>
- <xsl:copy-of select="current-group()"/>
- </xsl:element>
- </xsl:for-each-group>
+ <one>
+ <xsl:copy-of select="word[$filterCheck(., 'l')]"/>
+ </one>
+ <two>
+ <xsl:copy-of select="word[$filterCheck(., 'is')]"/>
+ </two>
+ <three>
+ <xsl:copy-of select="word[$filterCheck(., 'm')]"/>
+ </three>
</result>
</xsl:template>
diff --git a/tests/if_expr/test3.xsl b/tests/if_expr/test7.xsl
similarity index 54%
copy from tests/if_expr/test3.xsl
copy to tests/if_expr/test7.xsl
index ec49a577..021b611d 100644
--- a/tests/if_expr/test3.xsl
+++ b/tests/if_expr/test7.xsl
@@ -4,28 +4,30 @@
<!-- Author: mukulg@apache.org -->
- <!-- use with test1_c.xml -->
+ <!-- use with test1_f.xml -->
- <!-- An XSLT stylesheet, to test the XPath 3.1 "if" conditional
- expression, when used within xsl:for-each-group to transform
- the current-grouping-key() value. -->
+ <!-- Test case description : This XSLT stylesheet, searches an XML input
+ document's contents, for the keywords mentioned within an auxiliary
+ text file srch_file.txt and produces the search results as output
+ of XSLT transformation. -->
<xsl:output method="xml" indent="yes"/>
- <xsl:variable name="gThan" select="function($x, $y) { $x gt $y }"/>
-
- <xsl:template match="/elem">
- <result>
- <xsl:for-each-group select="item" group-by="$gThan(a, b)">
- <xsl:variable name="grtOrLess" select="if (string(current-grouping-key()) eq 'true')
- then 'greater'
- else 'lessOrEqual'"/>
- <xsl:element name="{normalize-space($grtOrLess)}">
- <xsl:attribute name="count" select="count(current-group())"/>
- <xsl:copy-of select="current-group()"/>
- </xsl:element>
- </xsl:for-each-group>
- </result>
+ <xsl:variable name="scfFileContents" select="unparsed-text('srch_file.txt')"/>
+
+ <xsl:variable name="filterCheck" select="function($str, $srch) { if (contains($str, $srch))
+ then true()
+ else false() }"/>
+
+ <xsl:template match="/">
+ <xsl:variable name="srchInp" select="/list/word"/>
+ <xsl:variable name="srchKeyWords" select="tokenize($scfFileContents, ',')"/>
+ <xsl:for-each select="$srchKeyWords">
+ <xsl:variable name="keyWord" select="."/>
+ <srchResult>
+ <xsl:copy-of select="$srchInp[$filterCheck(., $keyWord)]"/>
+ </srchResult>
+ </xsl:for-each>
</xsl:template>
<!--
diff --git a/tests/org/apache/xalan/xpath3/FnUnparsedTextTests.java b/tests/org/apache/xalan/xpath3/FnUnparsedTextTests.java
index 79fa68e1..9c4c4f1d 100644
--- a/tests/org/apache/xalan/xpath3/FnUnparsedTextTests.java
+++ b/tests/org/apache/xalan/xpath3/FnUnparsedTextTests.java
@@ -86,5 +86,15 @@ public class FnUnparsedTextTests extends XslTransformTestsUtil {
runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
}
+
+ @Test
+ public void xslFnUnparsedTextTest5() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_a.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test5.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test5.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
}
diff --git a/tests/org/apache/xalan/xpath3/IfExprTests.java b/tests/org/apache/xalan/xpath3/IfExprTests.java
index 4e422b93..e97a7a06 100644
--- a/tests/org/apache/xalan/xpath3/IfExprTests.java
+++ b/tests/org/apache/xalan/xpath3/IfExprTests.java
@@ -106,5 +106,25 @@ public class IfExprTests extends XslTransformTestsUtil {
runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
}
+
+ @Test
+ public void xslIfExprTest7() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_f.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test6.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test7.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
+
+ @Test
+ public void xslIfExprTest8() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_f.xml";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test7.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test8.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, null);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org