declare function local:getParentOfNonExistentChild($system as element(), $bValue as xs:string, $childName as xs:string) as element()*
{
$system//*[b/text() = $bValue][not($childName)]
};
<result>
{ local:getParentOfNonExistentChild($system treat as element(), "b2", "d") }
</result>
In this example the function accepts the name of the child. When I pass in "d" as the child name, it should have returned the first <a> parent, but the function always return empty.
This appears to be a variable substitution problem with the $childName.
How should I write this?
Subject:Find the parent who doesn't have a particular child Author:Ivan Pedruzzi Date:07 Jul 2009 02:09 AM
declare function local:getParentOfNonExistentChild(
$system as element(),
$bValue as xs:string,
$childName as xs:string) as element()*
{
$system//*[b/text() = $bValue and not(.//*[local-name() = $childName ])]
};