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 2025/05/06 11:41:38 UTC
(xalan-java) branch xalan-j_xslt3.0_mvn updated: committing fixes for few w3c xslt3 xsl:analyze-string instruction test cases from analyze-string-001 upto analyze-string-008
This is an automated email from the ASF dual-hosted git repository.
mukulg pushed a commit to branch xalan-j_xslt3.0_mvn
in repository https://gitbox.apache.org/repos/asf/xalan-java.git
The following commit(s) were added to refs/heads/xalan-j_xslt3.0_mvn by this push:
new 62cc8316d committing fixes for few w3c xslt3 xsl:analyze-string instruction test cases from analyze-string-001 upto analyze-string-008
62cc8316d is described below
commit 62cc8316dc6e4b6848d790c44b5bc2aff4ed72bf
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Tue May 6 17:11:20 2025 +0530
committing fixes for few w3c xslt3 xsl:analyze-string instruction test cases from analyze-string-001 upto analyze-string-008
---
.../apache/xalan/templates/ElemAnalyzeString.java | 47 ++++++---
.../org/apache/xalan/templates/ElemVariable.java | 15 ---
.../xpath/composite/SequenceTypeSupport.java | 107 +++++++++++++++++++--
.../xalan/tests/util/XslTransformTestsUtil.java | 2 +
.../tests/w3c/xslt3/XslAnalyzeStringTests.java | 1 -
.../resources/fn_tokenize/fn_tokenize_test10.xsl | 6 +-
6 files changed, 136 insertions(+), 42 deletions(-)
diff --git a/src/main/java/org/apache/xalan/templates/ElemAnalyzeString.java b/src/main/java/org/apache/xalan/templates/ElemAnalyzeString.java
index b60501e99..a05ace6f0 100644
--- a/src/main/java/org/apache/xalan/templates/ElemAnalyzeString.java
+++ b/src/main/java/org/apache/xalan/templates/ElemAnalyzeString.java
@@ -20,6 +20,7 @@ package org.apache.xalan.templates;
import java.util.ArrayList;
import java.util.List;
+import javax.xml.transform.SourceLocator;
import javax.xml.transform.TransformerException;
import org.apache.xalan.transformer.TransformerImpl;
@@ -29,13 +30,15 @@ import org.apache.xpath.ExpressionOwner;
import org.apache.xpath.XPath;
import org.apache.xpath.XPathContext;
import org.apache.xpath.functions.RegexEvaluationSupport;
+import org.apache.xpath.objects.ResultSequence;
+import org.apache.xpath.objects.XNumber;
import org.apache.xpath.objects.XObject;
import org.apache.xpath.regex.Matcher;
+import xml.xpath31.processor.types.XSNumericType;
+
/**
* Implementation of the XSLT 3.0 xsl:analyze-string instruction.
- *
- * Ref : https://www.w3.org/TR/xslt-30/#analyze-string
*
* @author Mukul Gandhi <mu...@apache.org>
*
@@ -198,18 +201,37 @@ public class ElemAnalyzeString extends ElemTemplateElement implements Expression
final XPathContext xctxt = transformer.getXPathContext();
+ SourceLocator srcLocator = xctxt.getSAXLocator();
+
XObject xpathSelectExpr = m_selectExpression.execute(xctxt);
+ if (xpathSelectExpr instanceof ResultSequence) {
+ ResultSequence rSeq = (ResultSequence)xpathSelectExpr;
+ if (rSeq.size() == 0) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The xsl:analyze-string/@select expression evaluated "
+ + "to an empty sequence.", srcLocator);
+ }
+ else if (rSeq.size() > 1) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The xsl:analyze-string/@select expression evaluated to a "
+ + "sequence with size greater than one.", srcLocator);
+ }
+ }
+
+ if ((xpathSelectExpr instanceof XNumber) || (xpathSelectExpr instanceof XSNumericType)) {
+ throw new javax.xml.transform.TransformerException("XPTY0004 : The xsl:analyze-string/@select expression has error. The supplied "
+ + "'select' expression evaluated to a numeric value, whereas the "
+ + "required type is xs:string.", srcLocator);
+ }
+
String strToBeAnalyzed = XslTransformEvaluationHelper.getStrVal(xpathSelectExpr);
if (m_regex == null) {
- throw new javax.xml.transform.TransformerException("XTSE0010 : xsl:analyze-string element must "
- + "have an 'regex' attribute.", xctxt.getSAXLocator());
+ throw new javax.xml.transform.TransformerException("XTSE0010 : xsl:analyze-string element must have an 'regex' attribute.", srcLocator);
}
if (m_regex_flags != null && !RegexEvaluationSupport.isFlagStrValid(m_regex_flags)) {
throw new javax.xml.transform.TransformerException("XTDE1145 : Incorrect regex flag value(s) are present as value of 'flags' "
- + "attribute of an xsl:analyze-string element.", xctxt.getSAXLocator());
+ + "attribute of an xsl:analyze-string element.", srcLocator);
}
ElemTemplateElement templateElem1 = this.m_firstChild;
@@ -217,29 +239,28 @@ public class ElemAnalyzeString extends ElemTemplateElement implements Expression
if (templateElem1 == null) {
throw new javax.xml.transform.TransformerException("XTSE1130 : At-least one of the elements xsl:matching-substring, or "
- + "xsl:non-matching-substring must be present as child of xsl:analyze-string "
- + "element.", xctxt.getSAXLocator());
+ + "xsl:non-matching-substring must be present as child of xsl:analyze-string "
+ + "element.", srcLocator);
}
else {
templateElem2 = templateElem1.m_nextSibling;
if (templateElem2 != null) {
if (!((templateElem1 instanceof ElemMatchingSubstring) && (templateElem2 instanceof ElemNonMatchingSubstring))) {
throw new javax.xml.transform.TransformerException("XTSE0010 : xsl:matching-substring element must come first within "
- + "xsl:analyze-string element.", xctxt.getSAXLocator());
+ + "xsl:analyze-string element.", srcLocator);
}
if (templateElem2.m_nextSibling != null) {
throw new javax.xml.transform.TransformerException("XTSE0010 : Only xsl:matching-substring, and xsl:non-matching-substring "
- + "elements are allowed to be present within an xsl:analyze-string "
- + "element.", xctxt.getSAXLocator());
+ + "elements are allowed to be present within an xsl:analyze-string "
+ + "element.", srcLocator);
}
}
}
if (strToBeAnalyzed.length() > 0) {
String regexStr = m_regex.evaluate(xctxt, xctxt.getContextNode(), this);
- Matcher regexMatcher = RegexEvaluationSupport.compileAndExecute(
- RegexEvaluationSupport.transformRegexStrForSubtractionOp(regexStr),
- m_regex_flags, strToBeAnalyzed);
+ Matcher regexMatcher = RegexEvaluationSupport.compileAndExecute(RegexEvaluationSupport.transformRegexStrForSubtractionOp(regexStr),
+ m_regex_flags, strToBeAnalyzed);
List<RegexMatchInfo> regexMatchInfoList = new ArrayList<RegexMatchInfo>();
diff --git a/src/main/java/org/apache/xalan/templates/ElemVariable.java b/src/main/java/org/apache/xalan/templates/ElemVariable.java
index 8b93d85eb..de31ed9d5 100644
--- a/src/main/java/org/apache/xalan/templates/ElemVariable.java
+++ b/src/main/java/org/apache/xalan/templates/ElemVariable.java
@@ -293,9 +293,6 @@ public class ElemVariable extends ElemTemplateElement
m_selectPattern = param.m_selectPattern;
m_qname = param.m_qname;
m_isTopLevel = param.m_isTopLevel;
-
- // m_value = param.m_value;
- // m_varContext = param.m_varContext;
}
/**
@@ -322,7 +319,6 @@ public class ElemVariable extends ElemTemplateElement
xpathVarMap.put(m_qname, var);
}
else {
- // transformer.getXPathContext().getVarStack().pushVariable(m_qname, var);
transformer.getXPathContext().getVarStack().setLocalVariable(m_index, var);
}
@@ -888,17 +884,6 @@ public class ElemVariable extends ElemTemplateElement
}
}
-
-
-// /**
-// * This after the template's children have been composed.
-// */
-// public void endCompose() throws TransformerException
-// {
-// super.endCompose();
-// }
-
-
/**
* If the children of a variable is a single xsl:value-of or text literal,
* it is cheaper to evaluate this as an expression, so try and adapt the
diff --git a/src/main/java/org/apache/xpath/composite/SequenceTypeSupport.java b/src/main/java/org/apache/xpath/composite/SequenceTypeSupport.java
index c4ee21073..ef7a08173 100644
--- a/src/main/java/org/apache/xpath/composite/SequenceTypeSupport.java
+++ b/src/main/java/org/apache/xpath/composite/SequenceTypeSupport.java
@@ -106,8 +106,6 @@ import xml.xpath31.processor.types.XSYearMonthDuration;
* This class provides few utility methods, to support
* evaluation of XPath 3.1 sequence type expressions.
*
- * Ref : https://www.w3.org/TR/xpath-31/#id-sequencetype-syntax
- *
* @author Mukul Gandhi <mu...@apache.org>
*
* @xsl.usage advanced
@@ -230,7 +228,11 @@ public class SequenceTypeSupport {
*
* @author Mukul Gandhi <mu...@apache.org>
*/
- public static class OccurrenceIndicator {
+ public static class OccurrenceIndicator {
+ // No occurrence indicator has been specified within an
+ // XSL stylesheet in a sequence type expression.
+ public static int ABSENT = 0;
+
// Represents the sequence type occurrence indicator '?'
public static int ZERO_OR_ONE = 1;
@@ -427,35 +429,35 @@ public class SequenceTypeSupport {
if (sequenceTypeXPathExprStr.endsWith("?") || sequenceTypeXPathExprStr.endsWith("*") || sequenceTypeXPathExprStr.endsWith("+")) {
expectedTypeStr = expectedTypeStr.substring(0, expectedTypeStr.length() - 1);
}
- throw new TransformerException("XTTE0570 : An item of type xs:gYearMonth cannot be converted to " + expectedTypeStr + " as specified by stylesheet.");
+ throw new TransformerException("XTTE0570 : An item of type xs:gYearMonth cannot be converted to " + expectedTypeStr + " as specified within an XSL stylesheet.");
}
else if ((xObj instanceof XSGYear) && (expectedType != XS_GYEAR)) {
String expectedTypeStr = sequenceTypeXPathExprStr;
if (sequenceTypeXPathExprStr.endsWith("?") || sequenceTypeXPathExprStr.endsWith("*") || sequenceTypeXPathExprStr.endsWith("+")) {
expectedTypeStr = expectedTypeStr.substring(0, expectedTypeStr.length() - 1);
}
- throw new TransformerException("XTTE0570 : An item of type xs:gYear cannot be converted to " + expectedTypeStr + " as specified by stylesheet.");
+ throw new TransformerException("XTTE0570 : An item of type xs:gYear cannot be converted to " + expectedTypeStr + " as specified within an XSL stylesheet.");
}
else if ((xObj instanceof XSGMonthDay) && (expectedType != XS_GMONTH_DAY)) {
String expectedTypeStr = sequenceTypeXPathExprStr;
if (sequenceTypeXPathExprStr.endsWith("?") || sequenceTypeXPathExprStr.endsWith("*") || sequenceTypeXPathExprStr.endsWith("+")) {
expectedTypeStr = expectedTypeStr.substring(0, expectedTypeStr.length() - 1);
}
- throw new TransformerException("XTTE0570 : An item of type xs:gMonthDay cannot be converted to " + expectedTypeStr + " as specified by stylesheet.");
+ throw new TransformerException("XTTE0570 : An item of type xs:gMonthDay cannot be converted to " + expectedTypeStr + " as specified within an XSL stylesheet.");
}
else if ((xObj instanceof XSGDay) && (expectedType != XS_GDAY)) {
String expectedTypeStr = sequenceTypeXPathExprStr;
if (sequenceTypeXPathExprStr.endsWith("?") || sequenceTypeXPathExprStr.endsWith("*") || sequenceTypeXPathExprStr.endsWith("+")) {
expectedTypeStr = expectedTypeStr.substring(0, expectedTypeStr.length() - 1);
}
- throw new TransformerException("XTTE0570 : An item of type xs:gDay cannot be converted to " + expectedTypeStr + " as specified by stylesheet.");
+ throw new TransformerException("XTTE0570 : An item of type xs:gDay cannot be converted to " + expectedTypeStr + " as specified within an XSL stylesheet.");
}
else if ((xObj instanceof XSGMonth) && (expectedType != XS_GMONTH)) {
String expectedTypeStr = sequenceTypeXPathExprStr;
if (sequenceTypeXPathExprStr.endsWith("?") || sequenceTypeXPathExprStr.endsWith("*") || sequenceTypeXPathExprStr.endsWith("+")) {
expectedTypeStr = expectedTypeStr.substring(0, expectedTypeStr.length() - 1);
}
- throw new TransformerException("XTTE0570 : An item of type xs:gMonth cannot be converted to " + expectedTypeStr + " as specified by stylesheet.");
+ throw new TransformerException("XTTE0570 : An item of type xs:gMonth cannot be converted to " + expectedTypeStr + " as specified within an XSL stylesheet.");
}
}
}
@@ -549,6 +551,65 @@ public class SequenceTypeSupport {
return result;
}
}
+ else if (sequenceTypeKindTest.getKindVal() == ELEMENT_KIND) {
+ if (srcValue instanceof XNodeSetForDOM) {
+ XNodeSetForDOM xNodeSetForDOM = (XNodeSetForDOM)srcValue;
+ Object obj1 = xNodeSetForDOM.object();
+ if (obj1 instanceof DTMNodeList) {
+ DTMNodeList dtmNodeList = (DTMNodeList)obj1;
+ DTMCursorIterator dtmCursorIter = dtmNodeList.getDTMIterator();
+ int nodeHandle = dtmCursorIter.nextNode();
+ DTM dtm = xctxt.getDTM(nodeHandle);
+ int childNodeHandle = dtm.getFirstChild(nodeHandle);
+ int nextSiblingNodeHandle = dtm.getNextSibling(childNodeHandle);
+ String nodeExpectedLocalName = sequenceTypeKindTest.getNodeLocalName();
+ String nodeExpectedNsUri = sequenceTypeKindTest.getNodeNsUri();
+ if ((childNodeHandle != DTM.NULL) && (nextSiblingNodeHandle == DTM.NULL) &&
+ ((itemTypeOccurenceIndicator == OccurrenceIndicator.ABSENT) ||
+ (itemTypeOccurenceIndicator == OccurrenceIndicator.ZERO_OR_ONE))) {
+ Node node = dtm.getNode(childNodeHandle);
+ String nodeLocalName = node.getLocalName();
+ String nodeNsUri = node.getNamespaceURI();
+ boolean isNodeNameOk = isNodeNameOk(nodeLocalName, nodeNsUri, nodeExpectedLocalName, nodeExpectedNsUri);
+ if (isNodeNameOk) {
+ result = new XMLNodeCursorImpl(childNodeHandle, xctxt);
+
+ return result;
+ }
+ }
+ else if ((childNodeHandle != DTM.NULL) && (nextSiblingNodeHandle != DTM.NULL) &&
+ ((itemTypeOccurenceIndicator == OccurrenceIndicator.ZERO_OR_MANY) ||
+ (itemTypeOccurenceIndicator == OccurrenceIndicator.ONE_OR_MANY))) {
+ List<Integer> seqNodeHandles = new ArrayList<Integer>();
+ Node node = dtm.getNode(childNodeHandle);
+ String nodeLocalName = node.getLocalName();
+ String nodeNsUri = node.getNamespaceURI();
+ boolean isNodeNameOk = isNodeNameOk(nodeLocalName, nodeNsUri, nodeExpectedLocalName, nodeExpectedNsUri);
+ if (isNodeNameOk) {
+ seqNodeHandles.add(Integer.valueOf(childNodeHandle));
+ }
+ node = dtm.getNode(nextSiblingNodeHandle);
+ isNodeNameOk = isNodeNameOk(nodeLocalName, nodeNsUri, nodeExpectedLocalName, nodeExpectedNsUri);
+ if (isNodeNameOk) {
+ seqNodeHandles.add(Integer.valueOf(nextSiblingNodeHandle));
+ }
+ while ((nextSiblingNodeHandle = dtm.getNextSibling(nextSiblingNodeHandle)) != DTM.NULL) {
+ node = dtm.getNode(nextSiblingNodeHandle);
+ isNodeNameOk = isNodeNameOk(nodeLocalName, nodeNsUri, nodeExpectedLocalName, nodeExpectedNsUri);
+ if (isNodeNameOk) {
+ seqNodeHandles.add(Integer.valueOf(nextSiblingNodeHandle));
+ }
+ }
+
+ if (seqNodeHandles.size() > 0) {
+ result = new XMLNodeCursorImpl(seqNodeHandles, xctxt);
+
+ return result;
+ }
+ }
+ }
+ }
+ }
else if (sequenceTypeKindTest.getKindVal() == DOCUMENT_KIND) {
if (srcValue instanceof XMLNodeCursorImpl) {
XMLNodeCursorImpl nodeSet1 = (XMLNodeCursorImpl)srcValue;
@@ -987,8 +1048,8 @@ public class SequenceTypeSupport {
return result;
}
-
- /**
+
+ /**
* Check whether, two XML namespace values are equal.
*/
public static boolean isTwoXmlNamespaceValuesEqual(String ns0, String ns1) {
@@ -1860,5 +1921,31 @@ public class SequenceTypeSupport {
return isXdmItemOneOfTheNodeKinds;
}
+
+ /**
+ * Check whether, an XML document input node's name conforms to the
+ * node's expected name specified within sequence type.
+ */
+ private static boolean isNodeNameOk(String nodeLocalName, String nodeNsUri, String nodeExpectedLocalName,
+ String nodeExpectedNsUri) {
+ boolean result = true;
+
+ if (!((nodeExpectedLocalName == null) || ("".equals(nodeExpectedLocalName)))) {
+ if (!nodeLocalName.equals(nodeExpectedLocalName)) {
+ result = false;
+ }
+ else if ((nodeNsUri != null) && (nodeExpectedNsUri == null)) {
+ result = false;
+ }
+ else if ((nodeExpectedNsUri != null) && (nodeNsUri == null)) {
+ result = false;
+ }
+ else if ((nodeExpectedNsUri != null) && (nodeNsUri != null) && !nodeExpectedNsUri.equals(nodeNsUri)) {
+ result = false;
+ }
+ }
+
+ return result;
+ }
}
diff --git a/src/test/java/org/apache/xalan/tests/util/XslTransformTestsUtil.java b/src/test/java/org/apache/xalan/tests/util/XslTransformTestsUtil.java
index d5f133be3..cc2c3600c 100644
--- a/src/test/java/org/apache/xalan/tests/util/XslTransformTestsUtil.java
+++ b/src/test/java/org/apache/xalan/tests/util/XslTransformTestsUtil.java
@@ -139,6 +139,8 @@ public class XslTransformTestsUtil extends FileComparisonUtil {
xslTransformerFactory.setErrorListener(xslTransformErrHandler);
Transformer transformer = xslTransformerFactory.newTransformer(xsltStreamSrc);
+
+ transformer.setErrorListener(xslTransformErrHandler);
setXslTransformProperties(transformer);
diff --git a/src/test/java/org/apache/xalan/tests/w3c/xslt3/XslAnalyzeStringTests.java b/src/test/java/org/apache/xalan/tests/w3c/xslt3/XslAnalyzeStringTests.java
index f799ec784..5ef8ca229 100644
--- a/src/test/java/org/apache/xalan/tests/w3c/xslt3/XslAnalyzeStringTests.java
+++ b/src/test/java/org/apache/xalan/tests/w3c/xslt3/XslAnalyzeStringTests.java
@@ -19,7 +19,6 @@ package org.apache.xalan.tests.w3c.xslt3;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
diff --git a/src/test/resources/fn_tokenize/fn_tokenize_test10.xsl b/src/test/resources/fn_tokenize/fn_tokenize_test10.xsl
index 1c6651fa1..85d1662f6 100644
--- a/src/test/resources/fn_tokenize/fn_tokenize_test10.xsl
+++ b/src/test/resources/fn_tokenize/fn_tokenize_test10.xsl
@@ -25,9 +25,9 @@
</result>
</xsl:template>
- <!-- An XSL named template that intends to emit a sequence of
- XML elements. This overall XSL transformation fails, because actual emitted
- elements don't conform to sequence return type of this XSL template. -->
+ <!-- An XSL named template that intends to emit a sequence of XML elements.
+ This overall XSL transformation fails, because actual emitted elements
+ don't conform to sequence return type of this XSL template. -->
<xsl:template name="emitStrTokensFromTokenSequence" as="element(incorrect_element_name)*">
<xsl:param name="tokens" as="xs:string*"/>
<xsl:for-each select="$tokens">
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org