tuxji commented on a change in pull request #373:
URL: https://github.com/apache/incubator-daffodil/pull/373#discussion_r416794287
##########
File path:
daffodil-runtime1/src/main/scala/org/apache/daffodil/dpath/FNFunctions.scala
##########
@@ -706,6 +706,92 @@ case class FNLocalName1(recipe: CompiledDPath, argType:
NodeInfo.Kind)
}
}
+/**
+ * Returns the namespace URI of the name of \$arg as an xs:anyURI
+ * 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:anyURI value.
+ *
+ * Otherwise, the result will be the namespace URI of the
+ * expanded-QName of the node identified by \$arg returned as an
+ * xs:anyURI 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]
+ *
+ * This function is called when 0 arguments are provided. We
+ * treat this as if the argument passed was "." to denote self.
+ */
+case class FNNamespaceUri0(recipe: CompiledDPath, argType: NodeInfo.Kind)
+ extends RecipeOpWithSubRecipes(recipe) {
+ override def run(dstate: DState) {
+ // Hook so we can insist this is non-constant at compile time
+ dstate.fnExists()
+ // Check that we have a current node, otherwise return empty string(URI)
+ if (dstate.currentNode eq null) {
+ dstate.setCurrentValue("")
+ }
+ else {
+ // Same as using "." to denote self.
+ val value: DataValueURI =
dstate.currentNode.namedQName.namespace.optURI.get
+ dstate.setCurrentValue(value)
+ }
+ }
+}
+
+/**
+ * Returns the namespace URI of the name of \$arg as an xs:anyURI
+ * value.
+ *
+ * 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:anyURI value.
+ *
+ * Otherwise, the result will be the namespace URI of the
+ * expanded-QName of the node identified by \$arg returned as an
+ * xs:anyURI value.
+ */
+case class FNNamespaceUri1(recipe: CompiledDPath, argType: NodeInfo.Kind)
+ extends FNOneArg(recipe, argType) {
+ override def computeValue(value: DataValuePrimitive, dstate: DState) = {
+ Assert.usageError("not to be called. DPath compiler should be answering
this without runtime calls.")
+ }
+
+ override def run(dstate: DState) {
+ // Hook so we can insist this is non-constant at compile time
+ dstate.fnExists()
+ // Save off original state, which is the original
+ // element/node that calls inputValueCalc with fn:namespace-uri.
Review comment:
Good to know, thanks! I'll make a similar change to FNLocalName.
----------------------------------------------------------------
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]