tuxji commented on a change in pull request #373:
URL: https://github.com/apache/incubator-daffodil/pull/373#discussion_r417380236



##########
File path: 
daffodil-runtime1/src/main/scala/org/apache/daffodil/dpath/FNFunctions.scala
##########
@@ -683,26 +683,109 @@ case class FNLocalName1(recipe: CompiledDPath, argType: 
NodeInfo.Kind)
   }
 
   override def run(dstate: DState) {
-    // Save off original state, which is the original
-    // element/node that calls inputValueCalc with fn:local-name
-    //
-    val origState = dstate
+    // Save off original node, which is the original
+    // element/node that calls fn:local-name
+    val savedNode = dstate.currentNode
 
     // Execute the recipe/expression which should
-    // return a node/element whose local-name we want.
-    //
+    // return a node/element whose local-name we want
     recipe.run(dstate)
 
     val localName = dstate.currentElement.name
+    dstate.setCurrentNode(savedNode)
 
     if (localName.contains(":"))
       throw new IllegalArgumentException("fn:local-name failed. " + localName 
+ " is not a valid NCName as it contains ':'.")
 
-    // The original state contains the node/element upon which
-    // fn:local-name was called.  This is where we should set
-    // the value.
-    //
-    origState.setCurrentValue(localName)
+    dstate.setCurrentValue(localName)
+  }
+}
+
+/**
+ * Returns the namespace URI of the name of \$arg as an xs:string
+ * value.
+ *
+ * If the argument is omitted, it defaults to the context item (.).
+ * The behavior of the function if the argument is omitted is
+ * exactly the same as if the context item had been passed as
+ * the argument.
+ *
+ * If the node identified by \$arg is neither an element nor an
+ * attribute node, or it is an element or attribute node whose
+ * expanded-QName is in no namespace, then the function returns
+ * the zero-length xs:string value.
+ *
+ * Otherwise, the result will be the namespace URI of the
+ * expanded-QName of the node identified by \$arg returned as an
+ * xs:string value.
+ *
+ * The following errors may be raised when \$arg is omitted:
+ * - If the context item is absent, dynamic error [err:XPDY002]
+ * - If the context item is not a node, type error [err:XPTY004]

Review comment:
       Yes, I agree with you about the type error XPTY004.  I was just looking 
through the DFDL spec this morning and I saw the following paragraph in 23. 
Expression Language:
   
   > DFDL implementations MUST comply with the error code behaviour in Appendix 
G of the XPath 2.0 spec and map these to the correct DFDL failure type. All but 
one of XPath's errors map to a schema definition error. The exception is 
XPTY0004, which is used both for static and dynamic cases of type mismatch. A 
static type mismatch maps to a schema definition error, whereas a dynamic type 
mismatch maps to a processing error. A DFDL implementation should distinguish 
the two kinds of XPTY0004 error if it is able to do so, but if unable it should 
map all XPTY0004 errors to a schema definition error.
   
   I'll issue a dstate.SDE if dstate.currentNode is null, saying something like 
(please suggest any better or more Daffodil-style way to say it):
   
   fn:namespace-uri [ context item | argument ] '%s' is not a node
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to