|
next
|
 Subject: xQuery 1.0 Produces XPTY0004 Error Author: Ethan Stein Date: 10 Jun 2009 04:00 PM Originally Posted: 10 Jun 2009 03:53 PM
|
When I try to run the below xquery from the command line using xquery 1.0, I get the following error
[XQuery][err:XPTY0004]Required item type of first argument of local:replaceNode() is element(*, xs:untyped); supplied value has item type element(PlanID)
My goal is to replace a specific node with three nodes. I can run it from Stylus Studio 2007 R2 without any problem, but from a command line, it produces the above error.
My xquery is
declare option ddtek:xml-streaming 'yes';
declare option ddtek:serialize "indent=yes, omit-xml-declaration=no";
declare variable $xPRSXMLInput as document-node(element(*, xs:untyped)) external;
declare function local:addPlanName($planNameNode as element(*, xs:untyped))
{
let $nodeName := name($planNameNode)
let $coverNode := concat($nodeName, "Cover")
let $tableHeaderNode := concat($nodeName, "TableHeader")
let $bodyTextNode := concat($nodeName, "BodyText")
let $planName := $planNameNode/text()
let $planName := fn:replace($planName, "AARP", "AARP®")
let $planName := fn:replace($planName, "MedicareComplete Essential", "MedicareComplete Essential®")
let $planName := fn:replace($planName, "Evercare", "Evercare®")
let $planName := fn:replace($planName, "MedicareComplete Choice", "MedicareComplete Choice®")
let $planName := fn:replace($planName, "Erickson Advantage", "Erickson Advantage®")
let $planName := fn:replace($planName, "SecureHorizons ", "SecureHorizons ®")
let $planName := fn:replace($planName, "MedicareComplete Plus", "MedicareComplete Plus™")
let $planName := fn:replace($planName, "MedicareComplete Value", "MedicareComplete Value™")
let $planName := fn:replace($planName, "MedicareComplete Premier", "MedicareComplete Premier™")
let $planName := fn:replace($planName, "MedicareComplete Balance", "MedicareComplete Balance™")
let $planName := fn:replace($planName, "MedicareComplete Mosaic", "MedicareComplete Mosaic™")
let $planName := fn:replace($planName, "MedicareDirect", "MedicareDirectࡈ")
return
if(fn:contains($planName, "MedicareComplete") and not(fn:contains($planName, "Essential")) and not(fn:contains($planName, "Choice")) and not(fn:contains($planName, "Plus")) and not(fn:contains($planName, "Value")) and not(fn:contains($planName, "Premier")) and not(fn:contains($planName, "Balance")) and not(fn:contains($planName, "Mosaic"))) then
let $planName := fn:replace($planName, "MedicareComplete", "MedicareComplete®")
return (
element { $nodeName } { $planNameNode/text() },
element { $coverNode } { concat("<p><span style="color:#000000;FONT-SIZE: 12pt;font-family:Times;">",$planName, "</p>") },
element { $tableHeaderNode } { concat("<p><span style="color:#000000;FONT-SIZE: 12pt;font-family:Times;">",$planName, "</p>") },
element { $bodyTextNode } { concat("<p><span style="color:#000000;FONT-SIZE: 12pt;font-family:Times;">",$planName, "</p>") }
)
else (
element { $nodeName } { $planNameNode/text() },
element { $coverNode } { concat("<p><span style="color:#000000;FONT-SIZE: 12pt;font-family:Times;">",$planName, "</p>") },
element { $tableHeaderNode } { concat("<p><span style="color:#000000;FONT-SIZE: 12pt;font-family:Times;">",$planName, "</p>") },
element { $bodyTextNode } { concat("<p><span style="color:#000000;FONT-SIZE: 12pt;font-family:Times;">",$planName, "</p>") }
)
};
declare function local:replaceNode($n as element(*, xs:untyped))
{
if (starts-with(upper-case(local-name($n)), "PLANNAME") and (not(ends-with(local-name($n),"Cover"))) and (not(ends-with(local-name($n),"TableHeader"))) and (not(ends-with(local-name($n),"BodyText")))) then local:addPlanName($n)
else (
element { name($n) } {$n/@*,
($n/text(),
for $child in $n/*
return local:replaceNode($child))}
)
};
<ExtractData>
{
for $CurrentYearPlan in $xPRSXMLInput/ExtractData/CurrentYearPlan
return
local:replaceNode($CurrentYearPlan)
}
</ExtractData>
And a sample XML input for xPRSXMLInput is a file containing:
<ExtractData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:/xPression/CustomerData/Schema/SB3_2.xsd">
<CurrentYearPlan>
<PlanID>H0303015</PlanID>
<ContractNumber>H0303</ContractNumber>
<PBPNumber>015</PBPNumber>
<BusinessSegment>Secure Horizons West</BusinessSegment>
<PlanType>HMO</PlanType>
<PlanDescription>Health Maintenace Organization</PlanDescription>
<SNPFlag>False</SNPFlag>
<PlanName1><p><span style="color:#000000;FONT-SIZE: 12pt;font-family:Times;">AARP MedicareComplete Choice Plan 2</p></PlanName1>
<PlanName2><p><span style="color:#FFFFFF;FONT-SIZE: 12pt;font-family:Arial;"><b>AARP MedicareComplete Choice Plan 2</b></p></PlanName2>
<LegalDescription>PACIFICARE OF ARIZONA, INC</LegalDescription>
<BrandName>AARP</BrandName>
<DrugCoverageType>MAPD</DrugCoverageType>
</CurrentYearPlan>
</ExtractData>
Please note, I do not have the option to upgrade to xQuery 2.0 and use Update Factory functionality. Therefore, recursion is my only option.
Please help.
|
|
|
|