![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a user-defined XPath function implemented using a custom context and the IXsltContextFunction interface. For its arguments, it accepts 3: { XPathResultType.Any, XPathResultType.Any, XPathResultType.String }. The function is called datediff, which converts the arguments to DateTimes, and gives args[0] - args[1] in the units specified by args[2] (e.g., "days", "months"). Anyhow, as an example, Let's say I have the following XML file: root testnode DateVal="2008-12-05T00:00:00" TestName="Whatever" / /root And I execute the expression: ' /root/ testnode[datediff("2008-12-25T00:00:00",@DateVal,"days") < 365]/ @TestName' which should return the TestName attribute of any nodes whose DateVals are within a year of 12/25/2008, give or take (for arguments sake, let's just assume the function returns 0 if args[1] > args[0]). The issue is that when the XPath function (datediff) Invoke is called, and I watch the args[] array, the second argument (@DateVal), is an XPathNodeIterator with one XPathNavigator (as it should be), but: The XPathNavigator is the testnode element not the DateVal attribute. Is this the expected behavior? Why is an element node being passed in as the argument, when, from the XPathExpression above, it's clearly the attribute node that's being passed as an argument to the function? By the way, I realize that I can pass "string(@EndDate)" as the second argument, which works fine, but a function I'm building now that returns a set representing a cross-product of node sets will need the ability to traverse through attribute nodes. |
#3
| |||
| |||
|
|
That's really weird. I'd like to hear the answer too. Btw, can you provide minimal repro? -- Oleg jakebbohio wrote: I have a user-defined XPath function implemented using a custom context and the IXsltContextFunction interface. For its arguments, it accepts 3: { XPathResultType.Any, XPathResultType.Any, XPathResultType.String }. The function is called datediff, which converts the arguments to DateTimes, and gives args[0] - args[1] in the units specified by args[2] (e.g., "days", "months"). Anyhow, as an example, Let's say I have the following XML file: root testnode DateVal="2008-12-05T00:00:00" TestName="Whatever" / /root And I execute the expression: ' /root/ testnode[datediff("2008-12-25T00:00:00",@DateVal,"days") < 365]/ @TestName' which should return the TestName attribute of any nodes whose DateVals are within a year of 12/25/2008, give or take (for arguments sake, let's just assume the function returns 0 if args[1] > args[0]). The issue is that when the XPath function (datediff) Invoke is called, and I watch the args[] array, the second argument (@DateVal), is an XPathNodeIterator with one XPathNavigator (as it should be), but: The XPathNavigator is the testnode element not the DateVal attribute. Is this the expected behavior? Why is an element node being passed in as the argument, when, from the XPathExpression above, it's clearly the attribute node that's being passed as an argument to the function? By the way, I realize that I can pass "string(@EndDate)" as the second argument, which works fine, but a function I'm building now that returns a set representing a cross-product of node sets will need the ability to traverse through attribute nodes. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |