[prev in list] [next in list] [prev in thread] [next in thread]
List: xalan-cvs
Subject: [xalan-java] branch xalan-j_xslt3.0 updated: doing few improvements to,
From: mukulg () apache ! org
Date: 2023-06-08 15:15:21
Message-ID: 168623732148.2684799.16291519623092565317 () gitbox2-he-fi ! apache ! org
[Download RAW message or body]
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 d3a4b1f2 doing few improvements to, existing xslt 3.0 and xpath 3.1 \
implementation for xalanj. minor modifications to existing test cases, and adding few \
new working test cases. d3a4b1f2 is described below
commit d3a4b1f2bb9e1d642b9ff839994edf824dc70558
Author: Mukul Gandhi <gandhi.mukul@gmail.com>
AuthorDate: Thu Jun 8 20:45:02 2023 +0530
doing few improvements to, existing xslt 3.0 and xpath 3.1 implementation for \
xalanj. minor modifications to existing test cases, and adding few new working test \
cases.
---
src/org/apache/xalan/templates/ElemForEach.java | 16 +++++---
src/org/apache/xalan/templates/ElemIf.java | 44 ++++++++++++++++-----
src/org/apache/xml/dtm/DTMManager.java | 45 +++++++++++-----------
src/org/apache/xpath/XPath.java | 1 -
src/org/apache/xpath/XPathContext.java | 38 ++++++++++++++++--
src/org/apache/xpath/functions/FuncLast.java | 10 +++--
src/org/apache/xpath/functions/FuncPosition.java | 14 +++++--
src/org/apache/xpath/xs/types/XSDuration.java | 5 +--
tests/analyze_string/test12.xsl | 6 ++-
tests/analyze_string/test13.xsl | 8 ++--
tests/fn_tokenize/test9.xsl | 34 +++++++++-------
tests/fn_unparsed_text/file_a1.txt | 8 ++++
tests/fn_unparsed_text/gold/test4.out | 7 ++++
tests/fn_unparsed_text/test3.xsl | 21 ++++------
tests/fn_unparsed_text/{test3.xsl => test4.xsl} | 38 +++++++-----------
.../apache/xalan/xpath3/FnUnparsedTextTests.java | 10 +++++
...FnUnparsedTextTests.java => SequenceTests.java} | 30 +++++----------
tests/org/apache/xalan/xslt3/AllXsl3Tests.java | 3 +-
tests/xsl_sequence/gold/test1.out | 12 ++++++
tests/xsl_sequence/gold/test2.out | 6 +++
.../test9.xsl => xsl_sequence/test1.xsl} | 29 +++++---------
tests/xsl_sequence/test1_a.xml | 2 +
.../test9.xsl => xsl_sequence/test2.xsl} | 33 +++++++---------
23 files changed, 249 insertions(+), 171 deletions(-)
diff --git a/src/org/apache/xalan/templates/ElemForEach.java \
b/src/org/apache/xalan/templates/ElemForEach.java index 663f867d..df4f3523 100644
--- a/src/org/apache/xalan/templates/ElemForEach.java
+++ b/src/org/apache/xalan/templates/ElemForEach.java
@@ -52,7 +52,6 @@ import org.apache.xpath.operations.Variable;
*
* @xsl.usage advanced
*/
-
/*
* Implementation of the XSLT 3.0 xsl:for-each instruction.
*/
@@ -343,6 +342,7 @@ public class ElemForEach extends ElemTemplateElement implements \
ExpressionOwner
XObject evalResult = ((Function)m_selectExpression).execute(xctxt);
if (evalResult instanceof ResultSequence) {
processResultSequence(transformer, xctxt, evalResult);
+ transformer.setXPathContext(xctxtOriginal);
return;
}
}
@@ -355,6 +355,7 @@ public class ElemForEach extends ElemTemplateElement implements \
ExpressionOwner
XObject evalResult = ((Variable)m_selectExpression).execute(xctxt);
if (evalResult instanceof ResultSequence) {
processResultSequence(transformer, xctxt, evalResult);
+ transformer.setXPathContext(xctxtOriginal);
return;
}
}
@@ -560,25 +561,28 @@ public class ElemForEach extends ElemTemplateElement implements \
ExpressionOwner }
/*
- * Process each of the XDM items in order, stored within a 'ResultSequence'
- * object, with the body of xsl:for-each element.
+ * Process each of the XDM items stored within a 'ResultSequence',
+ * in order, and apply each XDM item to all the XSLT instructions
+ * mentioned within body of current xsl:for-each element.
*/
private void processResultSequence(TransformerImpl transformer,
XPathContext xctxt, XObject evalResult)
- throws \
TransformerException {
-
+ throws \
TransformerException { ResultSequence resultSeq = (ResultSequence)evalResult;
List<XObject> resultSeqItems = resultSeq.getResultSequenceItems();
+ xctxt.setXPath3ContextSize(resultSeqItems.size());
+
for (int idx = 0; idx < resultSeqItems.size(); idx++) {
XObject resultSeqItem = resultSeqItems.get(idx);
xctxt.setXPath3ContextItem(resultSeqItem);
+ xctxt.setXPath3ContextPosition(idx + 1);
for (ElemTemplateElement elemTemplateElem = this.m_firstChild; \
elemTemplateElem != null;
elemTemplateElem = \
elemTemplateElem.m_nextSibling) { xctxt.setSAXLocator(elemTemplateElem);
transformer.setCurrentElement(elemTemplateElem);
- elemTemplateElem.execute(transformer);
+ elemTemplateElem.execute(transformer);
}
}
}
diff --git a/src/org/apache/xalan/templates/ElemIf.java \
b/src/org/apache/xalan/templates/ElemIf.java index e4f1ae05..74b2226f 100644
--- a/src/org/apache/xalan/templates/ElemIf.java
+++ b/src/org/apache/xalan/templates/ElemIf.java
@@ -23,20 +23,21 @@ package org.apache.xalan.templates;
import javax.xml.transform.TransformerException;
import org.apache.xalan.transformer.TransformerImpl;
+import org.apache.xml.dtm.DTM;
+import org.apache.xml.dtm.DTMManager;
import org.apache.xpath.XPath;
import org.apache.xpath.XPathContext;
import org.apache.xpath.objects.XObject;
/**
- * Implement xsl:if.
- * <pre>
- * <!ELEMENT xsl:if %template;>
- * <!ATTLIST xsl:if
- * test %expr; #REQUIRED
- * %space-att;
- * >
- * </pre>
- * @see <a href="http://www.w3.org/TR/xslt#section-Conditional-Processing-with-xsl:if">XXX \
in XSLT Specification</a> + * The XSLT xsl:if element, is used to perform conditional \
processing, + * within an XSLT stylesheet.
+ *
+ * <xsl:if
+ test = expression>
+ <!-- Content: sequence-constructor -->
+ </xsl:if>
+
* @xsl.usage advanced
*/
public class ElemIf extends ElemTemplateElement
@@ -157,9 +158,32 @@ public class ElemIf extends ElemTemplateElement
// transformer.getTraceManager().fireSelectedEvent(sourceNode, this,
// "endTest", m_test, test);
}
- else if (m_test.bool(xctxt, sourceNode, this))
+ /*else if (m_test.bool(xctxt, sourceNode, this))
{
transformer.executeChildTemplates(this, true);
+ }*/
+ else {
+ XObject xpath3ContextItem = xctxt.getXPath3ContextItem();
+ if (xpath3ContextItem != null) {
+ XPathContext xctxtNew = new XPathContext(false);
+ xctxtNew.setVarStack(xctxt.getVarStack());
+
+ xctxtNew.setXPath3ContextPosition(xctxt.getXPath3ContextPosition());
+ xctxtNew.setXPath3ContextSize(xctxt.getXPath3ContextSize());
+
+ DTMManager dtmMgr = xctxtNew.getDTMManager();
+ DTM docFragDtm = \
dtmMgr.createDTMForSimpleXMLDocument(xpath3ContextItem.str()); +
+ int contextNode = docFragDtm.getFirstChild(docFragDtm.getDocument()); \
+ xctxtNew.pushCurrentNode(contextNode);
+ xctxtNew.setSAXLocator(this);
+ if (m_test.bool(xctxtNew, contextNode, this)) {
+ transformer.executeChildTemplates(this, true);
+ }
+ }
+ else if (m_test.bool(xctxt, sourceNode, this)) {
+ transformer.executeChildTemplates(this, true);
+ }
}
}
diff --git a/src/org/apache/xml/dtm/DTMManager.java \
b/src/org/apache/xml/dtm/DTMManager.java index b8a149c9..4ad1169b 100644
--- a/src/org/apache/xml/dtm/DTMManager.java
+++ b/src/org/apache/xml/dtm/DTMManager.java
@@ -216,9 +216,8 @@ public abstract class DTMManager
/*
* This method constructs a DTM object representing an XML document.
- * The DTM instance that is constructed by this method, contains only
- * 'one xml element with a text node child'. This method currently
- * supports, evaluation of XSLT xsl:analyze-string instruction.
+ * The DTM object instance that is constructed by this method, contains
+ * only 'one xml element having a text node child'.
*
* @param strVal string value of the text node, that shall be available
* within this constructed DTM object.
@@ -227,29 +226,29 @@ public abstract class DTMManager
*
*/
public DTM createDTMForSimpleXMLDocument(String strVal) {
- try {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
+ dbf.setNamespaceAware(true);
- DocumentBuilder db = dbf.newDocumentBuilder();
- Document doc = db.newDocument();
- // we create a, temporary xml element name here. this xml
- // element name, is unlikely to be present within the xml
- // input document that is been transformed by an xslt
- // stylesheet.
- long currentTimeMills = System.currentTimeMillis();
- String elemNameSuffix = (Long.valueOf(currentTimeMills)).toString();
- Element elem = doc.createElement("t0_" + elemNameSuffix);
- Text textNode = doc.createTextNode(strVal);
- elem.appendChild(textNode);
- doc.appendChild(elem);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document doc = db.newDocument();
+ // we create a, temporary xml element name here. this xml
+ // element name, is unlikely to be present within the xml
+ // input document that is been transformed by an xslt
+ // stylesheet.
+ long currentTimeMills = System.currentTimeMillis();
+ String elemNameSuffix = (Long.valueOf(currentTimeMills)).toString();
+ Element elem = doc.createElement("t0_" + elemNameSuffix);
+ Text textNode = doc.createTextNode(strVal);
+ elem.appendChild(textNode);
+ doc.appendChild(elem);
- return getDTM(new DOMSource(doc), true, null, false, false);
- }
- catch (Exception ex) {
- throw new DTMException(ex);
- }
+ return getDTM(new DOMSource(doc), true, null, false, false);
+ }
+ catch (Exception ex) {
+ throw new DTMException(ex);
+ }
}
/**
diff --git a/src/org/apache/xpath/XPath.java b/src/org/apache/xpath/XPath.java
index 9a2b1b1e..ec3ac9e0 100644
--- a/src/org/apache/xpath/XPath.java
+++ b/src/org/apache/xpath/XPath.java
@@ -33,7 +33,6 @@ import org.apache.xml.utils.SAXSourceLocator;
import org.apache.xpath.compiler.Compiler;
import org.apache.xpath.compiler.FunctionTable;
import org.apache.xpath.compiler.XPathParser;
-import org.apache.xpath.functions.Function;
import org.apache.xpath.objects.XObject;
import org.apache.xpath.res.XPATHErrorResources;
diff --git a/src/org/apache/xpath/XPathContext.java \
b/src/org/apache/xpath/XPathContext.java index 2ca48c88..5ecccfc0 100644
--- a/src/org/apache/xpath/XPathContext.java
+++ b/src/org/apache/xpath/XPathContext.java
@@ -99,12 +99,28 @@ public class XPathContext extends DTMManager // implements \
ExpressionContext
*/
private boolean m_isSecureProcessing = false;
- // supporting XPath 3.1 context item, to be saved within current XPath context
+ /*
+ * data value, representing the XPath 3.1's current
+ * evaluation context item.
+ */
private XObject m_xpath3ContextItem = null;
/*
- * This field, can be used to store custom data (represented as a map object)
- * within the current XPath evaluation context.
+ * data value, representing the XPath 3.1's current
+ * evaluation context position.
+ */
+ private int m_xpath3ContextPosition = -1;
+
+ /*
+ * data value, representing the XPath 3.1's current
+ * evaluation context size.
+ */
+ private int m_xpath3ContextSize = -1;
+
+ /*
+ * this data value, can be used to store custom data
+ * (represented as a java.util.Map object) within the
+ * current XPath evaluation context.
*/
private Map<String, String> m_customDataMap = new HashMap<String, String>();
@@ -1384,6 +1400,22 @@ public class XPathContext extends DTMManager // implements \
ExpressionContext this.m_xpath3ContextItem = xpath3ContextItem;
}
+ public int getXPath3ContextPosition() {
+ return m_xpath3ContextPosition;
+ }
+
+ public void setXPath3ContextPosition(int xpath3ContextPosition) {
+ this.m_xpath3ContextPosition = xpath3ContextPosition;
+ }
+
+ public int getXPath3ContextSize() {
+ return m_xpath3ContextSize;
+ }
+
+ public void setXPath3ContextSize(int xpath3ContextSize) {
+ this.m_xpath3ContextSize = xpath3ContextSize;
+ }
+
public GregorianCalendar getCurrentDateTime() {
if (m_currentDateTime == null) {
m_currentDateTime = new GregorianCalendar(TimeZone.getDefault());
diff --git a/src/org/apache/xpath/functions/FuncLast.java \
b/src/org/apache/xpath/functions/FuncLast.java index 7adecda0..bf3eb9ac 100644
--- a/src/org/apache/xpath/functions/FuncLast.java
+++ b/src/org/apache/xpath/functions/FuncLast.java
@@ -27,14 +27,14 @@ import org.apache.xpath.compiler.Compiler;
import org.apache.xpath.objects.XNumber;
import org.apache.xpath.objects.XObject;
-
/**
- * Execute the Last() function.
+ * Execute the XPath 3.1 last() function.
+ *
* @xsl.usage advanced
*/
public class FuncLast extends Function
{
- static final long serialVersionUID = 9205812403085432943L;
+ static final long serialVersionUID = 9205812403085432943L;
private boolean m_isTopLevel;
@@ -59,6 +59,10 @@ public class FuncLast extends Function
public int getCountOfContextNodeList(XPathContext xctxt)
throws javax.xml.transform.TransformerException
{
+
+ if (xctxt.getXPath3ContextSize() != -1) {
+ return xctxt.getXPath3ContextSize();
+ }
// assert(null != m_contextNodeList, "m_contextNodeList must be non-null");
// If we're in a predicate, then this will return non-null.
diff --git a/src/org/apache/xpath/functions/FuncPosition.java \
b/src/org/apache/xpath/functions/FuncPosition.java index be0402dd..b5e6f1a3 100644
--- a/src/org/apache/xpath/functions/FuncPosition.java
+++ b/src/org/apache/xpath/functions/FuncPosition.java
@@ -29,12 +29,14 @@ import org.apache.xpath.objects.XNumber;
import org.apache.xpath.objects.XObject;
/**
- * Execute the Position() function.
+ * Execute the XPath 3.1 position() function.
+ *
* @xsl.usage advanced
*/
public class FuncPosition extends Function
{
- static final long serialVersionUID = -9092846348197271582L;
+ static final long serialVersionUID = -9092846348197271582L;
+
private boolean m_isTopLevel;
/**
@@ -51,12 +53,16 @@ public class FuncPosition extends Function
*
* @param xctxt Runtime XPath context.
*
- * @return The current position of the itteration in the context node list,
+ * @return The current position of the iteration in the context node list,
* or -1 if there is no active context node list.
*/
public int getPositionInContextNodeList(XPathContext xctxt)
{
-
+
+ if (xctxt.getXPath3ContextPosition() != -1) {
+ return xctxt.getXPath3ContextPosition();
+ }
+
// System.out.println("FuncPosition- entry");
// If we're in a predicate, then this will return non-null.
SubContextList iter = m_isTopLevel ? null : xctxt.getSubContextList();
diff --git a/src/org/apache/xpath/xs/types/XSDuration.java \
b/src/org/apache/xpath/xs/types/XSDuration.java index d75ab56b..72be5b33 100644
--- a/src/org/apache/xpath/xs/types/XSDuration.java
+++ b/src/org/apache/xpath/xs/types/XSDuration.java
@@ -153,7 +153,6 @@ public class XSDuration extends XSCtrType {
didSomething = true;
}
- // do the "time" bit
int hours = hours();
int minutes = minutes();
double seconds = seconds();
@@ -168,9 +167,7 @@ public class XSDuration extends XSCtrType {
}
if (seconds != 0) {
String doubStr = (new Double(seconds).toString());
- if (doubStr.endsWith(".0")) {
- // string value of x.0 seconds is xS. e.g, 7.0S is converted to
- // 7S.
+ if (doubStr.endsWith(".0")) {
tret += doubStr.substring(0, doubStr.indexOf(".0")) + "S";
} else {
tret += seconds + "S";
diff --git a/tests/analyze_string/test12.xsl b/tests/analyze_string/test12.xsl
index 3294cb2c..2f451386 100644
--- a/tests/analyze_string/test12.xsl
+++ b/tests/analyze_string/test12.xsl
@@ -5,7 +5,9 @@
<!-- Author: mukulg@apache.org -->
<!-- XSLT stylesheet to transform, date with string format '23 March 2002'
- to the string format '2002-03-23'. -->
+ to the string format '2002-03-23'.
+ Note the use of, double curly braces within xsl:analyze-string's regex,
+ because the regex attribute is an avt. -->
<xsl:output method="text"/>
@@ -14,7 +16,7 @@
<xsl:variable name="date1" select="'23 March 2002'"/>
<xsl:template match="/">
- <xsl:analyze-string select="$date1" \
regex="([0-9]{{1,2}})\s([A-Z][a-z]+)\s([0-9]{{4}})"> + \
<xsl:analyze-string select="normalize-space($date1)" \
regex="([0-9]{{1,2}})\s([A-Z][a-z]+)\s([0-9]{{4}})"> \
<xsl:matching-substring> <xsl:value-of select="regex-group(3)"/>
<xsl:text>-</xsl:text>
diff --git a/tests/analyze_string/test13.xsl b/tests/analyze_string/test13.xsl
index 099292ac..f7f6214d 100644
--- a/tests/analyze_string/test13.xsl
+++ b/tests/analyze_string/test13.xsl
@@ -7,8 +7,10 @@
<!-- use with test1_h.xml -->
<!-- XSLT stylesheet to transform, date with string format '23 March 2002'
- to the string format '2002-03-23'. This stylesheet, transforms sequence
- of xml 'date' elements. -->
+ to the string format '2002-03-23'.
+ Note the use of, double curly braces within xsl:analyze-string's regex,
+ because the regex attribute is an avt.
+ This stylesheet, transforms sequence of xml 'date' elements. -->
<xsl:output method="xml" indent="yes"/>
@@ -18,7 +20,7 @@
<result>
<xsl:for-each select="date">
<date>
- <xsl:analyze-string select="." \
regex="([0-9]{{1,2}})\s([A-Z][a-z]+)\s([0-9]{{4}})"> + \
<xsl:analyze-string select="normalize-space(.)" \
regex="([0-9]{{1,2}})\s([A-Z][a-z]+)\s([0-9]{{4}})"> \
<xsl:matching-substring> <xsl:value-of select="regex-group(3)"/>
<xsl:text>-</xsl:text>
diff --git a/tests/fn_tokenize/test9.xsl b/tests/fn_tokenize/test9.xsl
index b10859e7..103f2e9a 100644
--- a/tests/fn_tokenize/test9.xsl
+++ b/tests/fn_tokenize/test9.xsl
@@ -5,28 +5,36 @@
<!-- Author: mukulg@apache.org -->
<!-- use with test1_b.xml -->
+
+ <!-- this XSLT stylesheet, tests emitting specific items
+ from an XDM sequence to XSLT transformation's
+ output. -->
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/elem">
- <elem>
- <xsl:variable name="tokens">
- <xsl:for-each select="tokenize(str2, '\s+')">
- <item><xsl:value-of select="."/></item>
- </xsl:for-each>
- </xsl:variable>
- <!-- emitting specific items from resulting sequence (please
- see the previous xsl:variable evaluation), using following
- xslt template instructions. -->
+ <elem>
+ <xsl:variable name="tokens" select="tokenize(str2, '\s+')"/>
<result1>
- <xsl:copy-of select="$tokens/item[position() < 5]"/>
+ <xsl:for-each select="$tokens">
+ <xsl:if test="position() < 5">
+ <item><xsl:value-of select="."/></item>
+ </xsl:if>
+ </xsl:for-each>
</result1>
<result2>
- <xsl:copy-of select="$tokens/item[2] | $tokens/item[3]"/>
+ <xsl:for-each select="$tokens">
+ <xsl:if test="(position() = 2) or (position() = 3)">
+ <item><xsl:value-of select="."/></item>
+ </xsl:if>
+ </xsl:for-each>
</result2>
<result3>
- <xsl:copy-of select="$tokens/item[(position() != 1) and
- (position() != last())]"/>
+ <xsl:for-each select="$tokens">
+ <xsl:if test="(position() != 1) and (position() != last())">
+ <item><xsl:value-of select="."/></item>
+ </xsl:if>
+ </xsl:for-each>
</result3>
</elem>
</xsl:template>
diff --git a/tests/fn_unparsed_text/file_a1.txt b/tests/fn_unparsed_text/file_a1.txt
new file mode 100644
index 00000000..3a85c254
--- /dev/null
+++ b/tests/fn_unparsed_text/file_a1.txt
@@ -0,0 +1,8 @@
+hello world
+this is a test file that
+
+we'll use with an xslt transformation
+
+hello
+
+hi there
diff --git a/tests/fn_unparsed_text/gold/test4.out \
b/tests/fn_unparsed_text/gold/test4.out new file mode 100644
index 00000000..2522c389
--- /dev/null
+++ b/tests/fn_unparsed_text/gold/test4.out
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <line>hello world</line>
+ <line>this is a test file that</line>
+ <line>we'll use with an xslt transformation</line>
+ <line>hello</line>
+ <line>hi there</line>
+</result>
diff --git a/tests/fn_unparsed_text/test3.xsl b/tests/fn_unparsed_text/test3.xsl
index 989f2cbc..a968e4ca 100644
--- a/tests/fn_unparsed_text/test3.xsl
+++ b/tests/fn_unparsed_text/test3.xsl
@@ -14,20 +14,15 @@
<title/>
</head>
<body>
- <xsl:variable name="tokens">
- <xsl:for-each select="tokenize($fileContents, '\r?\n')">
- <token><xsl:value-of select="."/></token>
- </xsl:for-each>
- </xsl:variable>
- <xsl:for-each select="$tokens/token">
+ <xsl:for-each select="tokenize($fileContents, '\r?\n')">
<xsl:choose>
- <xsl:when test="position() < last()">
- <b><xsl:value-of select="string(.)"/></b>
- <br/>
- </xsl:when>
- <xsl:otherwise>
- <b><xsl:value-of select="string(.)"/></b>
- </xsl:otherwise>
+ <xsl:when test="position() < last()">
+ <b><xsl:value-of select="."/></b>
+ <br/>
+ </xsl:when>
+ <xsl:otherwise>
+ <b><xsl:value-of select="."/></b>
+ </xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</body>
diff --git a/tests/fn_unparsed_text/test3.xsl b/tests/fn_unparsed_text/test4.xsl
similarity index 56%
copy from tests/fn_unparsed_text/test3.xsl
copy to tests/fn_unparsed_text/test4.xsl
index 989f2cbc..dbd82e31 100644
--- a/tests/fn_unparsed_text/test3.xsl
+++ b/tests/fn_unparsed_text/test4.xsl
@@ -3,35 +3,23 @@
version="3.0">
<!-- Author: mukulg@apache.org -->
+
+ <!-- using XPath 3.1 function fn:unparsed-text to read a text file,
+ and producing an XSLT transformation output that doesn't contain
+ whitespace only or empty lines. -->
- <xsl:output method="html" indent="yes"/>
+ <xsl:output method="xml" indent="yes"/>
- <xsl:variable name="fileContents" select="unparsed-text('test_1.txt')"/>
+ <xsl:variable name="fileLines" \
select="tokenize(unparsed-text('file_a1.txt'),'\r?\n')"/>
<xsl:template match="/">
- <html>
- <head>
- <title/>
- </head>
- <body>
- <xsl:variable name="tokens">
- <xsl:for-each select="tokenize($fileContents, '\r?\n')">
- <token><xsl:value-of select="."/></token>
- </xsl:for-each>
- </xsl:variable>
- <xsl:for-each select="$tokens/token">
- <xsl:choose>
- <xsl:when test="position() < last()">
- <b><xsl:value-of select="string(.)"/></b>
- <br/>
- </xsl:when>
- <xsl:otherwise>
- <b><xsl:value-of select="string(.)"/></b>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- </body>
- </html>
+ <result>
+ <xsl:for-each select="$fileLines">
+ <xsl:if test="not(normalize-space() = '')">
+ <line><xsl:value-of select="."/></line>
+ </xsl:if>
+ </xsl:for-each>
+ </result>
</xsl:template>
<!--
diff --git a/tests/org/apache/xalan/xpath3/FnUnparsedTextTests.java \
b/tests/org/apache/xalan/xpath3/FnUnparsedTextTests.java index ba1f369a..79fa68e1 \
100644
--- a/tests/org/apache/xalan/xpath3/FnUnparsedTextTests.java
+++ b/tests/org/apache/xalan/xpath3/FnUnparsedTextTests.java
@@ -76,5 +76,15 @@ public class FnUnparsedTextTests extends XslTransformTestsUtil {
runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, \
null); }
+
+ @Test
+ public void xslFnUnparsedTextTest4() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test4.xsl";
+ String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test4.xsl";
+
+ String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test4.out";
+
+ runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, \
null); + }
}
diff --git a/tests/org/apache/xalan/xpath3/FnUnparsedTextTests.java \
b/tests/org/apache/xalan/xpath3/SequenceTests.java similarity index 73%
copy from tests/org/apache/xalan/xpath3/FnUnparsedTextTests.java
copy to tests/org/apache/xalan/xpath3/SequenceTests.java
index ba1f369a..56895112 100644
--- a/tests/org/apache/xalan/xpath3/FnUnparsedTextTests.java
+++ b/tests/org/apache/xalan/xpath3/SequenceTests.java
@@ -23,21 +23,21 @@ import org.junit.BeforeClass;
import org.junit.Test;
/**
- * XPath 3.1 function fn:unparsed-text test cases.
+ * XSLT 3.0 test cases, to test traversal of XDM sequences.
*
* @author Mukul Gandhi <mukulg@apache.org>
*
* @xsl.usage advanced
*/
-public class FnUnparsedTextTests extends XslTransformTestsUtil {
+public class SequenceTests extends XslTransformTestsUtil {
- private static final String XSL_TRANSFORM_INPUT_DIRPATH = \
XSLConstants.XSL_TRANSFORM_INPUT_DIRPATH_PREFIX + "fn_unparsed_text/"; + private \
static final String XSL_TRANSFORM_INPUT_DIRPATH = \
XSLConstants.XSL_TRANSFORM_INPUT_DIRPATH_PREFIX + "xsl_sequence/";
- private static final String XSL_TRANSFORM_GOLD_DIRPATH = \
XSLConstants.XSL_TRANSFORM_GOLD_DIRPATH_PREFIX + "fn_unparsed_text/gold/"; + \
private static final String XSL_TRANSFORM_GOLD_DIRPATH = \
XSLConstants.XSL_TRANSFORM_GOLD_DIRPATH_PREFIX + "xsl_sequence/gold/";
@BeforeClass
public static void setUpBeforeClass() throws Exception {
- // no op
+ // no op
}
@AfterClass
@@ -48,8 +48,8 @@ public class FnUnparsedTextTests extends XslTransformTestsUtil {
}
@Test
- public void xslFnUnparsedTextTest1() {
- String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xsl";
+ public void xslSequenceTest1() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_a.xml";
String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1.xsl";
String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test1.out"; \
@@ -58,23 +58,13 @@ public class FnUnparsedTextTests extends XslTransformTestsUtil {
}
@Test
- public void xslFnUnparsedTextTest2() {
- String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test2.xsl";
+ public void xslSequenceTest2() {
+ String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test1_a.xml";
String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test2.xsl";
String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test2.out"; \
- runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, \
null);
- }
-
- @Test
- public void xslFnUnparsedTextTest3() {
- String xmlFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test3.xsl";
- String xslFilePath = XSL_TRANSFORM_INPUT_DIRPATH + "test3.xsl";
-
- String goldFilePath = XSL_TRANSFORM_GOLD_DIRPATH + "test3.out";
-
- runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, goldFilePath, \
null); + runXslTransformAndAssertOutput(xmlFilePath, xslFilePath, \
goldFilePath, null); }
}
diff --git a/tests/org/apache/xalan/xslt3/AllXsl3Tests.java \
b/tests/org/apache/xalan/xslt3/AllXsl3Tests.java index 76506c68..6c68f421 100644
--- a/tests/org/apache/xalan/xslt3/AllXsl3Tests.java
+++ b/tests/org/apache/xalan/xslt3/AllXsl3Tests.java
@@ -21,6 +21,7 @@ import org.apache.xalan.xpath3.FnIndexOfTests;
import org.apache.xalan.xpath3.FnStringJoinTests;
import org.apache.xalan.xpath3.FnTokenizeTests;
import org.apache.xalan.xpath3.FnUnparsedTextTests;
+import org.apache.xalan.xpath3.SequenceTests;
import org.apache.xalan.xpath3.StringTests;
import org.apache.xalan.xpath3.XsConstructorFunctions;
import org.junit.runner.RunWith;
@@ -44,7 +45,7 @@ import org.junit.runners.Suite.SuiteClasses;
GroupingWithSortTests.class, RtfMigrationTests.class, \
QuantifiedExprTests.class,
FnUnparsedTextTests.class, FnTokenizeTests.class, \
FnStringJoinTests.class,
FnAbsTests.class, StringTests.class, XsConstructorFunctions.class,
- FnIndexOfTests.class })
+ FnIndexOfTests.class, SequenceTests.class })
public class AllXsl3Tests {
}
diff --git a/tests/xsl_sequence/gold/test1.out b/tests/xsl_sequence/gold/test1.out
new file mode 100644
index 00000000..777cc36a
--- /dev/null
+++ b/tests/xsl_sequence/gold/test1.out
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?><elem>
+ <token>a</token>
+ <token>b</token>
+ <token>c</token>
+ <token>d</token>
+ <token>e</token>
+ <token>f</token>
+ <token>g</token>
+ <token>h</token>
+ <token>i</token>
+ <token>j</token>
+</elem>
diff --git a/tests/xsl_sequence/gold/test2.out b/tests/xsl_sequence/gold/test2.out
new file mode 100644
index 00000000..41cdb339
--- /dev/null
+++ b/tests/xsl_sequence/gold/test2.out
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?><elem>
+ <token>a</token>
+ <token>b</token>
+ <token>c</token>
+ <token>d</token>
+</elem>
diff --git a/tests/fn_tokenize/test9.xsl b/tests/xsl_sequence/test1.xsl
similarity index 57%
copy from tests/fn_tokenize/test9.xsl
copy to tests/xsl_sequence/test1.xsl
index b10859e7..b895e56e 100644
--- a/tests/fn_tokenize/test9.xsl
+++ b/tests/xsl_sequence/test1.xsl
@@ -2,32 +2,21 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0">
- <!-- Author: mukulg@apache.org -->
+ <!-- Author: mukulg@apache.org -->
- <!-- use with test1_b.xml -->
+ <!-- use with test1_a.xml -->
+
+ <!-- demonstrating, traversing an XDM sequence comprising of
+ XPath 3.1 atomic values, using xsl:for-each instruction. -->
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/elem">
<elem>
- <xsl:variable name="tokens">
- <xsl:for-each select="tokenize(str2, '\s+')">
- <item><xsl:value-of select="."/></item>
- </xsl:for-each>
- </xsl:variable>
- <!-- emitting specific items from resulting sequence (please
- see the previous xsl:variable evaluation), using following
- xslt template instructions. -->
- <result1>
- <xsl:copy-of select="$tokens/item[position() < 5]"/>
- </result1>
- <result2>
- <xsl:copy-of select="$tokens/item[2] | $tokens/item[3]"/>
- </result2>
- <result3>
- <xsl:copy-of select="$tokens/item[(position() != 1) and
- (position() != last())]"/>
- </result3>
+ <xsl:variable name="tokens" select="tokenize(.,'\s+')"/>
+ <xsl:for-each select="$tokens">
+ <token><xsl:value-of select="."/></token>
+ </xsl:for-each>
</elem>
</xsl:template>
diff --git a/tests/xsl_sequence/test1_a.xml b/tests/xsl_sequence/test1_a.xml
new file mode 100644
index 00000000..0abfa59b
--- /dev/null
+++ b/tests/xsl_sequence/test1_a.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<elem>a b c d e f g h i j</elem>
\ No newline at end of file
diff --git a/tests/fn_tokenize/test9.xsl b/tests/xsl_sequence/test2.xsl
similarity index 57%
copy from tests/fn_tokenize/test9.xsl
copy to tests/xsl_sequence/test2.xsl
index b10859e7..21ba4956 100644
--- a/tests/fn_tokenize/test9.xsl
+++ b/tests/xsl_sequence/test2.xsl
@@ -2,32 +2,25 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0">
- <!-- Author: mukulg@apache.org -->
+ <!-- Author: mukulg@apache.org -->
- <!-- use with test1_b.xml -->
+ <!-- use with test1_a.xml -->
+
+ <!-- demonstrating, traversing an XDM sequence comprising of
+ XPath 3.1 atomic values, using xsl:for-each instruction and
+ using specific XDM items depending on their position within
+ the sequence. -->
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/elem">
<elem>
- <xsl:variable name="tokens">
- <xsl:for-each select="tokenize(str2, '\s+')">
- <item><xsl:value-of select="."/></item>
- </xsl:for-each>
- </xsl:variable>
- <!-- emitting specific items from resulting sequence (please
- see the previous xsl:variable evaluation), using following
- xslt template instructions. -->
- <result1>
- <xsl:copy-of select="$tokens/item[position() < 5]"/>
- </result1>
- <result2>
- <xsl:copy-of select="$tokens/item[2] | $tokens/item[3]"/>
- </result2>
- <result3>
- <xsl:copy-of select="$tokens/item[(position() != 1) and
- (position() != last())]"/>
- </result3>
+ <xsl:variable name="tokens" select="tokenize(.,'\s+')"/>
+ <xsl:for-each select="$tokens">
+ <xsl:if test="position() < 5">
+ <token><xsl:value-of select="."/></token>
+ </xsl:if>
+ </xsl:for-each>
</elem>
</xsl:template>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic