xpath.js 242 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466
  1. (function(){/*
  2. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3. *
  4. * Copyright (c) 2012 Sergey Ilinsky
  5. * Dual licensed under the MIT and GPL licenses.
  6. *
  7. *
  8. */
  9. // Javascript objects
  10. var cString = window.String,
  11. cBoolean = window.Boolean,
  12. cNumber = window.Number,
  13. cObject = window.Object,
  14. cArray = window.Array,
  15. cRegExp = window.RegExp,
  16. cDate = window.Date,
  17. cFunction = window.Function,
  18. cMath = window.Math,
  19. // Error Objects
  20. cError = window.Error,
  21. cSyntaxError= window.SyntaxError,
  22. cTypeError = window.TypeError,
  23. // misc
  24. fIsNaN = window.isNaN,
  25. fIsFinite = window.isFinite,
  26. nNaN = window.NaN,
  27. nInfinity = window.Infinity,
  28. // Functions
  29. fWindow_btoa = window.btoa,
  30. fWindow_atob = window.atob,
  31. fWindow_parseInt= window.parseInt,
  32. fString_trim =(function() {
  33. return cString.prototype.trim ? function(sValue) {return cString(sValue).trim();} : function(sValue) {
  34. return cString(sValue).replace(/^\s+|\s+$/g, '');
  35. };
  36. })(),
  37. fArray_indexOf =(function() {
  38. return cArray.prototype.indexOf ? function(aValue, vItem) {return aValue.indexOf(vItem);} : function(aValue, vItem) {
  39. for (var nIndex = 0, nLength = aValue.length; nIndex < nLength; nIndex++)
  40. if (aValue[nIndex] === vItem)
  41. return nIndex;
  42. return -1;
  43. };
  44. })();
  45. var sNS_XSD = "http://www.w3.org/2001/XMLSchema",
  46. sNS_XPF = "http://www.w3.org/2005/xpath-functions",
  47. sNS_XNS = "http://www.w3.org/2000/xmlns/",
  48. sNS_XML = "http://www.w3.org/XML/1998/namespace";
  49. /*
  50. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  51. *
  52. * Copyright (c) 2012 Sergey Ilinsky
  53. * Dual licensed under the MIT and GPL licenses.
  54. *
  55. *
  56. */
  57. function cException(sCode
  58. ) {
  59. this.code = sCode;
  60. this.message =
  61. oException_messages[sCode];
  62. };
  63. cException.prototype = new cError;
  64. // "http://www.w3.org/2005/xqt-errors"
  65. var oException_messages = {};
  66. oException_messages["XPDY0002"] = "Evaluation of an expression relies on some part of the dynamic context that has not been assigned a value.";
  67. oException_messages["XPST0003"] = "Expression is not a valid instance of the grammar";
  68. oException_messages["XPTY0004"] = "Type is not appropriate for the context in which the expression occurs";
  69. oException_messages["XPST0008"] = "Expression refers to an element name, attribute name, schema type name, namespace prefix, or variable name that is not defined in the static context";
  70. oException_messages["XPST0010"] = "Axis not supported";
  71. oException_messages["XPST0017"] = "Expanded QName and number of arguments in a function call do not match the name and arity of a function signature";
  72. oException_messages["XPTY0018"] = "The result of the last step in a path expression contains both nodes and atomic values";
  73. oException_messages["XPTY0019"] = "The result of a step (other than the last step) in a path expression contains an atomic value.";
  74. oException_messages["XPTY0020"] = "In an axis step, the context item is not a node.";
  75. oException_messages["XPST0051"] = "It is a static error if a QName that is used as an AtomicType in a SequenceType is not defined in the in-scope schema types as an atomic type.";
  76. oException_messages["XPST0081"] = "A QName used in an expression contains a namespace prefix that cannot be expanded into a namespace URI by using the statically known namespaces.";
  77. //
  78. oException_messages["FORG0001"] = "Invalid value for cast/constructor.";
  79. oException_messages["FORG0003"] = "fn:zero-or-one called with a sequence containing more than one item.";
  80. oException_messages["FORG0004"] = "fn:one-or-more called with a sequence containing no items.";
  81. oException_messages["FORG0005"] = "fn:exactly-one called with a sequence containing zero or more than one item.";
  82. oException_messages["FORG0006"] = "Invalid argument type.";
  83. //
  84. oException_messages["FODC0001"] = "No context document.";
  85. //
  86. oException_messages["FORX0001"] = "Invalid regular expression flags.";
  87. //
  88. oException_messages["FOCA0002"] = "Invalid lexical value.";
  89. //
  90. oException_messages["FOCH0002"] = "Unsupported collation.";
  91. oException_messages["FONS0004"] = "No namespace found for prefix.";
  92. /*
  93. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  94. *
  95. * Copyright (c) 2012 Sergey Ilinsky
  96. * Dual licensed under the MIT and GPL licenses.
  97. *
  98. *
  99. */
  100. function cLexer(sValue) {
  101. var aMatch = sValue.match(/\$?(?:(?![0-9-])(?:\w[\w.-]*|\*):)?(?![0-9-])(?:\w[\w.-]*|\*)|\(:|:\)|\/\/|\.\.|::|\d+(?:\.\d*)?(?:[eE][+-]?\d+)?|\.\d+(?:[eE][+-]?\d+)?|"[^"]*(?:""[^"]*)*"|'[^']*(?:''[^']*)*'|<<|>>|[!<>]=|(?![0-9-])[\w-]+:\*|\s+|./g);
  102. if (aMatch) {
  103. var nStack = 0;
  104. for (var nIndex = 0, nLength = aMatch.length; nIndex < nLength; nIndex++)
  105. if (aMatch[nIndex] == '(:')
  106. nStack++;
  107. else
  108. if (aMatch[nIndex] == ':)' && nStack)
  109. nStack--;
  110. else
  111. if (!nStack && !/^\s/.test(aMatch[nIndex]))
  112. this[this.length++] = aMatch[nIndex];
  113. if (nStack)
  114. throw new cException("XPST0003"
  115. );
  116. }
  117. };
  118. cLexer.prototype.index = 0;
  119. cLexer.prototype.length = 0;
  120. cLexer.prototype.reset = function() {
  121. this.index = 0;
  122. };
  123. cLexer.prototype.peek = function(nOffset) {
  124. return this[this.index +(nOffset || 0)] || '';
  125. };
  126. cLexer.prototype.next = function(nOffset) {
  127. return(this.index+= nOffset || 1) < this.length;
  128. };
  129. cLexer.prototype.back = function(nOffset) {
  130. return(this.index-= nOffset || 1) > 0;
  131. };
  132. cLexer.prototype.eof = function() {
  133. return this.index >= this.length;
  134. };
  135. /*
  136. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  137. *
  138. * Copyright (c) 2012 Sergey Ilinsky
  139. * Dual licensed under the MIT and GPL licenses.
  140. *
  141. *
  142. */
  143. function cDOMAdapter() {
  144. };
  145. // Custom members
  146. cDOMAdapter.prototype.isNode = function(oNode) {
  147. return oNode &&!!oNode.nodeType;
  148. };
  149. cDOMAdapter.prototype.getProperty = function(oNode, sName) {
  150. return oNode[sName];
  151. };
  152. // Standard members
  153. cDOMAdapter.prototype.isSameNode = function(oNode, oNode2) {
  154. return oNode == oNode2;
  155. };
  156. cDOMAdapter.prototype.compareDocumentPosition = function(oNode, oNode2) {
  157. return oNode.compareDocumentPosition(oNode2);
  158. };
  159. cDOMAdapter.prototype.lookupNamespaceURI = function(oNode, sPrefix) {
  160. return oNode.lookupNamespaceURI(sPrefix);
  161. };
  162. // Document object members
  163. cDOMAdapter.prototype.getElementById = function(oNode, sId) {
  164. return oNode.getElementById(sId);
  165. };
  166. // Element/Document object members
  167. cDOMAdapter.prototype.getElementsByTagNameNS = function(oNode, sNameSpaceURI, sLocalName) {
  168. return oNode.getElementsByTagNameNS(sNameSpaceURI, sLocalName);
  169. };
  170. /*
  171. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  172. *
  173. * Copyright (c) 2012 Sergey Ilinsky
  174. * Dual licensed under the MIT and GPL licenses.
  175. *
  176. *
  177. */
  178. function cDynamicContext(oStaticContext, vItem, oScope, oDOMAdapter) {
  179. //
  180. this.staticContext = oStaticContext;
  181. //
  182. this.item = vItem;
  183. //
  184. this.scope = oScope || {};
  185. this.stack = {};
  186. //
  187. this.DOMAdapter = oDOMAdapter || new cDOMAdapter;
  188. //
  189. var oDate = new cDate,
  190. nOffset = oDate.getTimezoneOffset();
  191. this.dateTime = new cXSDateTime(oDate.getFullYear(), oDate.getMonth() + 1, oDate.getDate(), oDate.getHours(), oDate.getMinutes(), oDate.getSeconds() + oDate.getMilliseconds() / 1000, -nOffset);
  192. this.timezone = new cXSDayTimeDuration(0, cMath.abs(~~(nOffset / 60)), cMath.abs(nOffset % 60), 0, nOffset > 0);
  193. };
  194. cDynamicContext.prototype.item = null;
  195. cDynamicContext.prototype.position = 0;
  196. cDynamicContext.prototype.size = 0;
  197. //
  198. cDynamicContext.prototype.scope = null;
  199. cDynamicContext.prototype.stack = null; // Variables stack
  200. //
  201. cDynamicContext.prototype.dateTime = null;
  202. cDynamicContext.prototype.timezone = null;
  203. //
  204. cDynamicContext.prototype.staticContext = null;
  205. // Stack management
  206. cDynamicContext.prototype.pushVariable = function(sName, vValue) {
  207. if (!this.stack.hasOwnProperty(sName))
  208. this.stack[sName] = [];
  209. this.stack[sName].push(this.scope[sName]);
  210. this.scope[sName] = vValue;
  211. };
  212. cDynamicContext.prototype.popVariable = function(sName) {
  213. if (this.stack.hasOwnProperty(sName)) {
  214. this.scope[sName] = this.stack[sName].pop();
  215. if (!this.stack[sName].length) {
  216. delete this.stack[sName];
  217. if (typeof this.scope[sName] == "undefined")
  218. delete this.scope[sName];
  219. }
  220. }
  221. };
  222. /*
  223. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  224. *
  225. * Copyright (c) 2012 Sergey Ilinsky
  226. * Dual licensed under the MIT and GPL licenses.
  227. *
  228. *
  229. */
  230. function cStaticContext() {
  231. this.dataTypes = {};
  232. this.documents = {};
  233. this.functions = {};
  234. this.collations = {};
  235. this.collections= {};
  236. };
  237. cStaticContext.prototype.baseURI = null;
  238. //
  239. cStaticContext.prototype.dataTypes = null;
  240. cStaticContext.prototype.documents = null;
  241. //
  242. cStaticContext.prototype.functions = null;
  243. cStaticContext.prototype.defaultFunctionNamespace = null;
  244. //
  245. cStaticContext.prototype.collations = null;
  246. cStaticContext.prototype.defaultCollationName = sNS_XPF + "/collation/codepoint";
  247. //
  248. cStaticContext.prototype.collections = null;
  249. //
  250. cStaticContext.prototype.namespaceResolver = null;
  251. cStaticContext.prototype.defaultElementNamespace = null;
  252. //
  253. var rStaticContext_uri = /^(?:\{([^\}]+)\})?(.+)$/;
  254. //
  255. cStaticContext.prototype.setDataType = function(sUri, fFunction) {
  256. var aMatch = sUri.match(rStaticContext_uri);
  257. if (aMatch)
  258. if (aMatch[1] != sNS_XSD)
  259. this.dataTypes[sUri] = fFunction;
  260. };
  261. cStaticContext.prototype.getDataType = function(sUri) {
  262. var aMatch = sUri.match(rStaticContext_uri);
  263. if (aMatch)
  264. return aMatch[1] == sNS_XSD ? hStaticContext_dataTypes[aMatch[2]] : this.dataTypes[sUri];
  265. };
  266. cStaticContext.prototype.setDocument = function(sUri, fFunction) {
  267. this.documents[sUri] = fFunction;
  268. };
  269. cStaticContext.prototype.getDocument = function(sUri) {
  270. return this.documents[sUri];
  271. };
  272. cStaticContext.prototype.setFunction = function(sUri, fFunction) {
  273. var aMatch = sUri.match(rStaticContext_uri);
  274. if (aMatch)
  275. if (aMatch[1] != sNS_XPF)
  276. this.functions[sUri] = fFunction;
  277. };
  278. cStaticContext.prototype.getFunction = function(sUri) {
  279. var aMatch = sUri.match(rStaticContext_uri);
  280. if (aMatch)
  281. return aMatch[1] == sNS_XPF ? hStaticContext_functions[aMatch[2]] : this.functions[sUri];
  282. };
  283. cStaticContext.prototype.setCollation = function(sUri, fFunction) {
  284. this.collations[sUri] = fFunction;
  285. };
  286. cStaticContext.prototype.getCollation = function(sUri) {
  287. return this.collations[sUri];
  288. };
  289. cStaticContext.prototype.setCollection = function(sUri, fFunction) {
  290. this.collections[sUri] = fFunction;
  291. };
  292. cStaticContext.prototype.getCollection = function(sUri) {
  293. return this.collections[sUri];
  294. };
  295. cStaticContext.prototype.getURIForPrefix = function(sPrefix) {
  296. var oResolver = this.namespaceResolver,
  297. fResolver = oResolver && oResolver.lookupNamespaceURI ? oResolver.lookupNamespaceURI : oResolver,
  298. sNameSpaceURI;
  299. if (fResolver instanceof cFunction && (sNameSpaceURI = fResolver.call(oResolver, sPrefix)))
  300. return sNameSpaceURI;
  301. if (sPrefix == 'fn')
  302. return sNS_XPF;
  303. if (sPrefix == 'xs')
  304. return sNS_XSD;
  305. if (sPrefix == "xml")
  306. return sNS_XML;
  307. if (sPrefix == "xmlns")
  308. return sNS_XNS;
  309. //
  310. throw new cException("XPST0081"
  311. );
  312. };
  313. // Static members
  314. //Converts non-null JavaScript object to XML Schema object
  315. cStaticContext.js2xs = function(vItem) {
  316. // Convert types from JavaScript to XPath 2.0
  317. if (typeof vItem == "boolean")
  318. vItem = new cXSBoolean(vItem);
  319. else
  320. if (typeof vItem == "number")
  321. vItem =(fIsNaN(vItem) ||!fIsFinite(vItem)) ? new cXSDouble(vItem) : fNumericLiteral_parseValue(cString(vItem));
  322. else
  323. vItem = new cXSString(cString(vItem));
  324. //
  325. return vItem;
  326. };
  327. // Converts non-null XML Schema object to JavaScript object
  328. cStaticContext.xs2js = function(vItem) {
  329. if (vItem instanceof cXSBoolean)
  330. vItem = vItem.valueOf();
  331. else
  332. if (fXSAnyAtomicType_isNumeric(vItem))
  333. vItem = vItem.valueOf();
  334. else
  335. vItem = vItem.toString();
  336. //
  337. return vItem;
  338. };
  339. // System functions with signatures, operators and types
  340. var hStaticContext_functions = {},
  341. hStaticContext_signatures = {},
  342. hStaticContext_dataTypes = {},
  343. hStaticContext_operators = {};
  344. function fStaticContext_defineSystemFunction(sName, aParameters, fFunction) {
  345. // Register function
  346. hStaticContext_functions[sName] = fFunction;
  347. // Register signature
  348. hStaticContext_signatures[sName] = aParameters;
  349. };
  350. function fStaticContext_defineSystemDataType(sName, fFunction) {
  351. // Register dataType
  352. hStaticContext_dataTypes[sName] = fFunction;
  353. };
  354. /*
  355. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  356. *
  357. * Copyright (c) 2012 Sergey Ilinsky
  358. * Dual licensed under the MIT and GPL licenses.
  359. *
  360. *
  361. */
  362. function cExpression(sExpression, oStaticContext) {
  363. var oLexer = new cLexer(sExpression),
  364. oExpr = fExpr_parse(oLexer, oStaticContext);
  365. //
  366. if (!oLexer.eof())
  367. throw new cException("XPST0003"
  368. );
  369. //
  370. if (!oExpr)
  371. throw new cException("XPST0003"
  372. );
  373. this.internalExpression = oExpr;
  374. };
  375. cExpression.prototype.internalExpression = null;
  376. // Public methods
  377. cExpression.prototype.evaluate = function(oContext) {
  378. return this.internalExpression.evaluate(oContext);
  379. };
  380. /*
  381. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  382. *
  383. * Copyright (c) 2012 Sergey Ilinsky
  384. * Dual licensed under the MIT and GPL licenses.
  385. *
  386. *
  387. */
  388. function cStringCollator() {
  389. };
  390. cStringCollator.prototype.equals = function(sValue1, sValue2) {
  391. throw "Not implemented";
  392. };
  393. cStringCollator.prototype.compare = function(sValue1, sValue2) {
  394. throw "Not implemented";
  395. };
  396. /*
  397. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  398. *
  399. * Copyright (c) 2012 Sergey Ilinsky
  400. * Dual licensed under the MIT and GPL licenses.
  401. *
  402. *
  403. */
  404. function cXSConstants(){};
  405. // XML Schema 1.0 Datatypes
  406. cXSConstants.ANYSIMPLETYPE_DT = 1;
  407. cXSConstants.STRING_DT = 2;
  408. cXSConstants.BOOLEAN_DT = 3;
  409. cXSConstants.DECIMAL_DT = 4;
  410. cXSConstants.FLOAT_DT = 5;
  411. cXSConstants.DOUBLE_DT = 6;
  412. cXSConstants.DURATION_DT = 7;
  413. cXSConstants.DATETIME_DT = 8;
  414. cXSConstants.TIME_DT = 9;
  415. cXSConstants.DATE_DT = 10;
  416. cXSConstants.GYEARMONTH_DT = 11;
  417. cXSConstants.GYEAR_DT = 12;
  418. cXSConstants.GMONTHDAY_DT = 13;
  419. cXSConstants.GDAY_DT = 14;
  420. cXSConstants.GMONTH_DT = 15;
  421. cXSConstants.HEXBINARY_DT = 16;
  422. cXSConstants.BASE64BINARY_DT = 17;
  423. cXSConstants.ANYURI_DT = 18;
  424. cXSConstants.QNAME_DT = 19;
  425. cXSConstants.NOTATION_DT = 20;
  426. cXSConstants.NORMALIZEDSTRING_DT = 21;
  427. cXSConstants.TOKEN_DT = 22;
  428. cXSConstants.LANGUAGE_DT = 23;
  429. cXSConstants.NMTOKEN_DT = 24;
  430. cXSConstants.NAME_DT = 25;
  431. cXSConstants.NCNAME_DT = 26;
  432. cXSConstants.ID_DT = 27;
  433. cXSConstants.IDREF_DT = 28;
  434. cXSConstants.ENTITY_DT = 29;
  435. cXSConstants.INTEGER_DT = 30;
  436. cXSConstants.NONPOSITIVEINTEGER_DT = 31;
  437. cXSConstants.NEGATIVEINTEGER_DT = 32;
  438. cXSConstants.LONG_DT = 33;
  439. cXSConstants.INT_DT = 34;
  440. cXSConstants.SHORT_DT = 35;
  441. cXSConstants.BYTE_DT = 36;
  442. cXSConstants.NONNEGATIVEINTEGER_DT = 37;
  443. cXSConstants.UNSIGNEDLONG_DT = 38;
  444. cXSConstants.UNSIGNEDINT_DT = 39;
  445. cXSConstants.UNSIGNEDSHORT_DT = 40;
  446. cXSConstants.UNSIGNEDBYTE_DT = 41;
  447. cXSConstants.POSITIVEINTEGER_DT = 42;
  448. cXSConstants.LISTOFUNION_DT = 43;
  449. cXSConstants.LIST_DT = 44;
  450. cXSConstants.UNAVAILABLE_DT = 45;
  451. // XML Schema 1.1 Datatypes
  452. cXSConstants.DATETIMESTAMP_DT = 46;
  453. cXSConstants.DAYMONTHDURATION_DT = 47;
  454. cXSConstants.DAYTIMEDURATION_DT = 48;
  455. cXSConstants.PRECISIONDECIMAL_DT = 49;
  456. cXSConstants.ANYATOMICTYPE_DT = 50;
  457. cXSConstants.ANYTYPE_DT = 51;
  458. //
  459. cXSConstants.XT_YEARMONTHDURATION_DT=-1;
  460. cXSConstants.XT_UNTYPEDATOMIC_DT =-2;
  461. /*
  462. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  463. *
  464. * Copyright (c) 2012 Sergey Ilinsky
  465. * Dual licensed under the MIT and GPL licenses.
  466. *
  467. *
  468. */
  469. function cExpr() {
  470. this.items = [];
  471. };
  472. cExpr.prototype.items = null;
  473. // Static members
  474. function fExpr_parse (oLexer, oStaticContext) {
  475. var oItem;
  476. if (oLexer.eof() ||!(oItem = fExprSingle_parse(oLexer, oStaticContext)))
  477. return;
  478. // Create expression
  479. var oExpr = new cExpr;
  480. oExpr.items.push(oItem);
  481. while (oLexer.peek() == ',') {
  482. oLexer.next();
  483. if (oLexer.eof() ||!(oItem = fExprSingle_parse(oLexer, oStaticContext)))
  484. throw new cException("XPST0003"
  485. );
  486. oExpr.items.push(oItem);
  487. }
  488. return oExpr;
  489. };
  490. // Public members
  491. cExpr.prototype.evaluate = function(oContext) {
  492. var oSequence = [];
  493. for (var nIndex = 0, nLength = this.items.length; nIndex < nLength; nIndex++)
  494. oSequence = hStaticContext_operators["concatenate"].call(oContext, oSequence, this.items[nIndex].evaluate(oContext));
  495. return oSequence;
  496. };
  497. /*
  498. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  499. *
  500. * Copyright (c) 2012 Sergey Ilinsky
  501. * Dual licensed under the MIT and GPL licenses.
  502. *
  503. *
  504. */
  505. function cExprSingle() {
  506. };
  507. // Static members
  508. function fExprSingle_parse (oLexer, oStaticContext) {
  509. if (!oLexer.eof())
  510. return fIfExpr_parse(oLexer, oStaticContext)
  511. || fForExpr_parse(oLexer, oStaticContext)
  512. || fQuantifiedExpr_parse(oLexer, oStaticContext)
  513. || fOrExpr_parse(oLexer, oStaticContext);
  514. };
  515. /*
  516. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  517. *
  518. * Copyright (c) 2012 Sergey Ilinsky
  519. * Dual licensed under the MIT and GPL licenses.
  520. *
  521. *
  522. */
  523. function cForExpr() {
  524. this.bindings = [];
  525. this.returnExpr = null;
  526. };
  527. cForExpr.prototype.bindings = null;
  528. cForExpr.prototype.returnExpr = null;
  529. // Static members
  530. function fForExpr_parse (oLexer, oStaticContext) {
  531. if (oLexer.peek() == "for" && oLexer.peek(1).substr(0, 1) == '$') {
  532. oLexer.next();
  533. var oForExpr = new cForExpr,
  534. oExpr;
  535. do {
  536. oForExpr.bindings.push(fSimpleForBinding_parse(oLexer, oStaticContext));
  537. }
  538. while (oLexer.peek() == ',' && oLexer.next());
  539. if (oLexer.peek() != "return")
  540. throw new cException("XPST0003"
  541. );
  542. oLexer.next();
  543. if (oLexer.eof() ||!(oExpr = fExprSingle_parse(oLexer, oStaticContext)))
  544. throw new cException("XPST0003"
  545. );
  546. oForExpr.returnExpr = oExpr;
  547. return oForExpr;
  548. }
  549. };
  550. // Public members
  551. // for $x in X, $y in Y, $z in Z return $x + $y + $z
  552. // for $x in X return for $y in Y return for $z in Z return $x + $y + $z
  553. cForExpr.prototype.evaluate = function (oContext) {
  554. var oSequence = [];
  555. (function(oSelf, nBinding) {
  556. var oBinding = oSelf.bindings[nBinding++],
  557. oSequence1 = oBinding.inExpr.evaluate(oContext),
  558. sUri = (oBinding.namespaceURI ? '{' + oBinding.namespaceURI + '}' : '') + oBinding.localName;
  559. for (var nIndex = 0, nLength = oSequence1.length; nIndex < nLength; nIndex++) {
  560. oContext.pushVariable(sUri, oSequence1[nIndex]);
  561. if (nBinding < oSelf.bindings.length)
  562. arguments.callee(oSelf, nBinding);
  563. else
  564. oSequence = oSequence.concat(oSelf.returnExpr.evaluate(oContext));
  565. oContext.popVariable(sUri);
  566. }
  567. })(this, 0);
  568. return oSequence;
  569. };
  570. //
  571. function cSimpleForBinding(sPrefix, sLocalName, sNameSpaceURI, oInExpr) {
  572. this.prefix = sPrefix;
  573. this.localName = sLocalName;
  574. this.namespaceURI = sNameSpaceURI;
  575. this.inExpr = oInExpr;
  576. };
  577. cSimpleForBinding.prototype.prefix = null;
  578. cSimpleForBinding.prototype.localName = null;
  579. cSimpleForBinding.prototype.namespaceURI = null;
  580. cSimpleForBinding.prototype.inExpr = null;
  581. function fSimpleForBinding_parse (oLexer, oStaticContext) {
  582. var aMatch = oLexer.peek().substr(1).match(rNameTest);
  583. if (!aMatch)
  584. throw new cException("XPST0003"
  585. );
  586. if (aMatch[1] == '*' || aMatch[2] == '*')
  587. throw new cException("XPST0003"
  588. );
  589. oLexer.next();
  590. if (oLexer.peek() != "in")
  591. throw new cException("XPST0003"
  592. );
  593. oLexer.next();
  594. var oExpr;
  595. if (oLexer.eof() ||!(oExpr = fExprSingle_parse(oLexer, oStaticContext)))
  596. throw new cException("XPST0003"
  597. );
  598. return new cSimpleForBinding(aMatch[1] || null, aMatch[2], aMatch[1] ? oStaticContext.getURIForPrefix(aMatch[1]) : null, oExpr);
  599. };
  600. /*
  601. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  602. *
  603. * Copyright (c) 2012 Sergey Ilinsky
  604. * Dual licensed under the MIT and GPL licenses.
  605. *
  606. *
  607. */
  608. function cIfExpr(oCondExpr, oThenExpr, oElseExpr) {
  609. this.condExpr = oCondExpr;
  610. this.thenExpr = oThenExpr;
  611. this.elseExpr = oElseExpr;
  612. };
  613. cIfExpr.prototype.condExpr = null;
  614. cIfExpr.prototype.thenExpr = null;
  615. cIfExpr.prototype.elseExpr = null;
  616. // Static members
  617. function fIfExpr_parse (oLexer, oStaticContext) {
  618. var oCondExpr,
  619. oThenExpr,
  620. oElseExpr;
  621. if (oLexer.peek() == "if" && oLexer.peek(1) == '(') {
  622. oLexer.next(2);
  623. //
  624. if (oLexer.eof() ||!(oCondExpr = fExpr_parse(oLexer, oStaticContext)))
  625. throw new cException("XPST0003"
  626. );
  627. //
  628. if (oLexer.peek() != ')')
  629. throw new cException("XPST0003"
  630. );
  631. oLexer.next();
  632. if (oLexer.peek() != "then")
  633. throw new cException("XPST0003"
  634. );
  635. oLexer.next();
  636. if (oLexer.eof() ||!(oThenExpr = fExprSingle_parse(oLexer, oStaticContext)))
  637. throw new cException("XPST0003"
  638. );
  639. if (oLexer.peek() != "else")
  640. throw new cException("XPST0003"
  641. );
  642. oLexer.next();
  643. if (oLexer.eof() ||!(oElseExpr = fExprSingle_parse(oLexer, oStaticContext)))
  644. throw new cException("XPST0003"
  645. );
  646. //
  647. return new cIfExpr(oCondExpr, oThenExpr, oElseExpr);
  648. }
  649. };
  650. // Public members
  651. cIfExpr.prototype.evaluate = function (oContext) {
  652. return this[fFunction_sequence_toEBV(this.condExpr.evaluate(oContext), oContext) ? "thenExpr" : "elseExpr"].evaluate(oContext);
  653. };
  654. /*
  655. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  656. *
  657. * Copyright (c) 2012 Sergey Ilinsky
  658. * Dual licensed under the MIT and GPL licenses.
  659. *
  660. *
  661. */
  662. function cQuantifiedExpr(sQuantifier) {
  663. this.quantifier = sQuantifier;
  664. this.bindings = [];
  665. this.satisfiesExpr = null;
  666. };
  667. cQuantifiedExpr.prototype.bindings = null;
  668. cQuantifiedExpr.prototype.quantifier = null;
  669. cQuantifiedExpr.prototype.satisfiesExpr = null;
  670. // Static members
  671. function fQuantifiedExpr_parse (oLexer, oStaticContext) {
  672. var sQuantifier = oLexer.peek();
  673. if ((sQuantifier == "some" || sQuantifier == "every") && oLexer.peek(1).substr(0, 1) == '$') {
  674. oLexer.next();
  675. var oQuantifiedExpr = new cQuantifiedExpr(sQuantifier),
  676. oExpr;
  677. do {
  678. oQuantifiedExpr.bindings.push(fSimpleQuantifiedBinding_parse(oLexer, oStaticContext));
  679. }
  680. while (oLexer.peek() == ',' && oLexer.next());
  681. if (oLexer.peek() != "satisfies")
  682. throw new cException("XPST0003"
  683. );
  684. oLexer.next();
  685. if (oLexer.eof() ||!(oExpr = fExprSingle_parse(oLexer, oStaticContext)))
  686. throw new cException("XPST0003"
  687. );
  688. oQuantifiedExpr.satisfiesExpr = oExpr;
  689. return oQuantifiedExpr;
  690. }
  691. };
  692. // Public members
  693. cQuantifiedExpr.prototype.evaluate = function (oContext) {
  694. // TODO: re-factor
  695. var bEvery = this.quantifier == "every",
  696. bResult = bEvery ? true : false;
  697. (function(oSelf, nBinding) {
  698. var oBinding = oSelf.bindings[nBinding++],
  699. oSequence1 = oBinding.inExpr.evaluate(oContext),
  700. sUri = (oBinding.namespaceURI ? '{' + oBinding.namespaceURI + '}' : '') + oBinding.localName;
  701. for (var nIndex = 0, nLength = oSequence1.length; (nIndex < nLength) && (bEvery ? bResult :!bResult); nIndex++) {
  702. oContext.pushVariable(sUri, oSequence1[nIndex]);
  703. if (nBinding < oSelf.bindings.length)
  704. arguments.callee(oSelf, nBinding);
  705. else
  706. bResult = fFunction_sequence_toEBV(oSelf.satisfiesExpr.evaluate(oContext), oContext);
  707. oContext.popVariable(sUri);
  708. }
  709. })(this, 0);
  710. return [new cXSBoolean(bResult)];
  711. };
  712. //
  713. function cSimpleQuantifiedBinding(sPrefix, sLocalName, sNameSpaceURI, oInExpr) {
  714. this.prefix = sPrefix;
  715. this.localName = sLocalName;
  716. this.namespaceURI = sNameSpaceURI;
  717. this.inExpr = oInExpr;
  718. };
  719. cSimpleQuantifiedBinding.prototype.prefix = null;
  720. cSimpleQuantifiedBinding.prototype.localName = null;
  721. cSimpleQuantifiedBinding.prototype.namespaceURI = null;
  722. cSimpleQuantifiedBinding.prototype.inExpr = null;
  723. function fSimpleQuantifiedBinding_parse (oLexer, oStaticContext) {
  724. var aMatch = oLexer.peek().substr(1).match(rNameTest);
  725. if (!aMatch)
  726. throw new cException("XPST0003"
  727. );
  728. if (aMatch[1] == '*' || aMatch[2] == '*')
  729. throw new cException("XPST0003"
  730. );
  731. oLexer.next();
  732. if (oLexer.peek() != "in")
  733. throw new cException("XPST0003"
  734. );
  735. oLexer.next();
  736. var oExpr;
  737. if (oLexer.eof() ||!(oExpr = fExprSingle_parse(oLexer, oStaticContext)))
  738. throw new cException("XPST0003"
  739. );
  740. return new cSimpleQuantifiedBinding(aMatch[1] || null, aMatch[2], aMatch[1] ? oStaticContext.getURIForPrefix(aMatch[1]) : null, oExpr);
  741. };
  742. /*
  743. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  744. *
  745. * Copyright (c) 2012 Sergey Ilinsky
  746. * Dual licensed under the MIT and GPL licenses.
  747. *
  748. *
  749. */
  750. function cComparisonExpr(oLeft, oRight, sOperator) {
  751. this.left = oLeft;
  752. this.right = oRight;
  753. this.operator = sOperator;
  754. };
  755. cComparisonExpr.prototype.left = null;
  756. cComparisonExpr.prototype.right = null;
  757. cComparisonExpr.prototype.operator = null;
  758. // Static members
  759. function fComparisonExpr_parse (oLexer, oStaticContext) {
  760. var oExpr,
  761. oRight;
  762. if (oLexer.eof() ||!(oExpr = fRangeExpr_parse(oLexer, oStaticContext)))
  763. return;
  764. if (!(oLexer.peek() in hComparisonExpr_operators))
  765. return oExpr;
  766. // Comparison expression
  767. var sOperator = oLexer.peek();
  768. oLexer.next();
  769. if (oLexer.eof() ||!(oRight = fRangeExpr_parse(oLexer, oStaticContext)))
  770. throw new cException("XPST0003"
  771. );
  772. return new cComparisonExpr(oExpr, oRight, sOperator);
  773. };
  774. // Public members
  775. cComparisonExpr.prototype.evaluate = function (oContext) {
  776. var oResult = hComparisonExpr_operators[this.operator](this, oContext);
  777. return oResult == null ? [] : [oResult];
  778. };
  779. // General comparison
  780. function fComparisonExpr_GeneralComp(oExpr, oContext) {
  781. var oLeft = fFunction_sequence_atomize(oExpr.left.evaluate(oContext), oContext);
  782. if (!oLeft.length)
  783. return new cXSBoolean(false);
  784. var oRight = fFunction_sequence_atomize(oExpr.right.evaluate(oContext), oContext);
  785. if (!oRight.length)
  786. return new cXSBoolean(false);
  787. var bResult = false;
  788. for (var nLeftIndex = 0, nLeftLength = oLeft.length, bLeft, vLeft; (nLeftIndex < nLeftLength) &&!bResult; nLeftIndex++) {
  789. for (var nRightIndex = 0, nRightLength = oRight.length, bRight, vRight; (nRightIndex < nRightLength) &&!bResult; nRightIndex++) {
  790. vLeft = oLeft[nLeftIndex];
  791. vRight = oRight[nRightIndex];
  792. bLeft = vLeft instanceof cXSUntypedAtomic;
  793. bRight = vRight instanceof cXSUntypedAtomic;
  794. if (bLeft && bRight) {
  795. // cast xs:untypedAtomic to xs:string
  796. vLeft = cXSString.cast(vLeft);
  797. vRight = cXSString.cast(vRight);
  798. }
  799. else {
  800. //
  801. if (bLeft) {
  802. // Special: durations
  803. if (vRight instanceof cXSDayTimeDuration)
  804. vLeft = cXSDayTimeDuration.cast(vLeft);
  805. else
  806. if (vRight instanceof cXSYearMonthDuration)
  807. vLeft = cXSYearMonthDuration.cast(vLeft);
  808. else
  809. //
  810. if (vRight.primitiveKind)
  811. vLeft = hStaticContext_dataTypes[vRight.primitiveKind].cast(vLeft);
  812. }
  813. else
  814. if (bRight) {
  815. // Special: durations
  816. if (vLeft instanceof cXSDayTimeDuration)
  817. vRight = cXSDayTimeDuration.cast(vRight);
  818. else
  819. if (vLeft instanceof cXSYearMonthDuration)
  820. vRight = cXSYearMonthDuration.cast(vRight);
  821. else
  822. //
  823. if (vLeft.primitiveKind)
  824. vRight = hStaticContext_dataTypes[vLeft.primitiveKind].cast(vRight);
  825. }
  826. // cast xs:anyURI to xs:string
  827. if (vLeft instanceof cXSAnyURI)
  828. vLeft = cXSString.cast(vLeft);
  829. if (vRight instanceof cXSAnyURI)
  830. vRight = cXSString.cast(vRight);
  831. }
  832. bResult = hComparisonExpr_ValueComp_operators[hComparisonExpr_GeneralComp_map[oExpr.operator]](vLeft, vRight, oContext).valueOf();
  833. }
  834. }
  835. return new cXSBoolean(bResult);
  836. };
  837. var hComparisonExpr_GeneralComp_map = {
  838. '=': 'eq',
  839. '!=': 'ne',
  840. '>': 'gt',
  841. '<': 'lt',
  842. '>=': 'ge',
  843. '<=': 'le'
  844. };
  845. // Value comparison
  846. function fComparisonExpr_ValueComp(oExpr, oContext) {
  847. var oLeft = fFunction_sequence_atomize(oExpr.left.evaluate(oContext), oContext);
  848. if (!oLeft.length)
  849. return null;
  850. // Assert cardinality
  851. fFunctionCall_assertSequenceCardinality(oContext, oLeft, '?'
  852. );
  853. var oRight = fFunction_sequence_atomize(oExpr.right.evaluate(oContext), oContext);
  854. if (!oRight.length)
  855. return null;
  856. // Assert cardinality
  857. fFunctionCall_assertSequenceCardinality(oContext, oRight, '?'
  858. );
  859. var vLeft = oLeft[0],
  860. vRight = oRight[0];
  861. // cast xs:untypedAtomic to xs:string
  862. if (vLeft instanceof cXSUntypedAtomic)
  863. vLeft = cXSString.cast(vLeft);
  864. if (vRight instanceof cXSUntypedAtomic)
  865. vRight = cXSString.cast(vRight);
  866. // cast xs:anyURI to xs:string
  867. if (vLeft instanceof cXSAnyURI)
  868. vLeft = cXSString.cast(vLeft);
  869. if (vRight instanceof cXSAnyURI)
  870. vRight = cXSString.cast(vRight);
  871. //
  872. return hComparisonExpr_ValueComp_operators[oExpr.operator](vLeft, vRight, oContext);
  873. };
  874. //
  875. var hComparisonExpr_ValueComp_operators = {};
  876. hComparisonExpr_ValueComp_operators['eq'] = function(oLeft, oRight, oContext) {
  877. var sOperator = '';
  878. if (fXSAnyAtomicType_isNumeric(oLeft)) {
  879. if (fXSAnyAtomicType_isNumeric(oRight))
  880. sOperator = "numeric-equal";
  881. }
  882. else
  883. if (oLeft instanceof cXSBoolean) {
  884. if (oRight instanceof cXSBoolean)
  885. sOperator = "boolean-equal";
  886. }
  887. else
  888. if (oLeft instanceof cXSString) {
  889. if (oRight instanceof cXSString)
  890. return hStaticContext_operators["numeric-equal"].call(oContext, hStaticContext_functions["compare"].call(oContext, oLeft, oRight), new cXSInteger(0));
  891. }
  892. else
  893. if (oLeft instanceof cXSDate) {
  894. if (oRight instanceof cXSDate)
  895. sOperator = "date-equal";
  896. }
  897. else
  898. if (oLeft instanceof cXSTime) {
  899. if (oRight instanceof cXSTime)
  900. sOperator = "time-equal";
  901. }
  902. else
  903. if (oLeft instanceof cXSDateTime) {
  904. if (oRight instanceof cXSDateTime)
  905. sOperator = "dateTime-equal";
  906. }
  907. else
  908. if (oLeft instanceof cXSDuration) {
  909. if (oRight instanceof cXSDuration)
  910. sOperator = "duration-equal";
  911. }
  912. else
  913. if (oLeft instanceof cXSGYearMonth) {
  914. if (oRight instanceof cXSGYearMonth)
  915. sOperator = "gYearMonth-equal";
  916. }
  917. else
  918. if (oLeft instanceof cXSGYear) {
  919. if (oRight instanceof cXSGYear)
  920. sOperator = "gYear-equal";
  921. }
  922. else
  923. if (oLeft instanceof cXSGMonthDay) {
  924. if (oRight instanceof cXSGMonthDay)
  925. sOperator = "gMonthDay-equal";
  926. }
  927. else
  928. if (oLeft instanceof cXSGMonth) {
  929. if (oRight instanceof cXSGMonth)
  930. sOperator = "gMonth-equal";
  931. }
  932. else
  933. if (oLeft instanceof cXSGDay) {
  934. if (oRight instanceof cXSGDay)
  935. sOperator = "gDay-equal";
  936. }
  937. // skipped: xs:anyURI (covered by xs:string)
  938. else
  939. if (oLeft instanceof cXSQName) {
  940. if (oRight instanceof cXSQName)
  941. sOperator = "QName-equal";
  942. }
  943. else
  944. if (oLeft instanceof cXSHexBinary) {
  945. if (oRight instanceof cXSHexBinary)
  946. sOperator = "hexBinary-equal";
  947. }
  948. else
  949. if (oLeft instanceof cXSBase64Binary) {
  950. if (oRight instanceof cXSBase64Binary)
  951. sOperator = "base64Binary-equal";
  952. }
  953. // Call operator function
  954. if (sOperator)
  955. return hStaticContext_operators[sOperator].call(oContext, oLeft, oRight);
  956. // skipped: xs:NOTATION
  957. throw new cException("XPTY0004"
  958. ); // Cannot compare {type1} to {type2}
  959. };
  960. hComparisonExpr_ValueComp_operators['ne'] = function(oLeft, oRight, oContext) {
  961. return new cXSBoolean(!hComparisonExpr_ValueComp_operators['eq'](oLeft, oRight, oContext).valueOf());
  962. };
  963. hComparisonExpr_ValueComp_operators['gt'] = function(oLeft, oRight, oContext) {
  964. var sOperator = '';
  965. if (fXSAnyAtomicType_isNumeric(oLeft)) {
  966. if (fXSAnyAtomicType_isNumeric(oRight))
  967. sOperator = "numeric-greater-than";
  968. }
  969. else
  970. if (oLeft instanceof cXSBoolean) {
  971. if (oRight instanceof cXSBoolean)
  972. sOperator = "boolean-greater-than";
  973. }
  974. else
  975. if (oLeft instanceof cXSString) {
  976. if (oRight instanceof cXSString)
  977. return hStaticContext_operators["numeric-greater-than"].call(oContext, hStaticContext_functions["compare"].call(oContext, oLeft, oRight), new cXSInteger(0));
  978. }
  979. else
  980. if (oLeft instanceof cXSDate) {
  981. if (oRight instanceof cXSDate)
  982. sOperator = "date-greater-than";
  983. }
  984. else
  985. if (oLeft instanceof cXSTime) {
  986. if (oRight instanceof cXSTime)
  987. sOperator = "time-greater-than";
  988. }
  989. else
  990. if (oLeft instanceof cXSDateTime) {
  991. if (oRight instanceof cXSDateTime)
  992. sOperator = "dateTime-greater-than";
  993. }
  994. else
  995. if (oLeft instanceof cXSYearMonthDuration) {
  996. if (oRight instanceof cXSYearMonthDuration)
  997. sOperator = "yearMonthDuration-greater-than";
  998. }
  999. else
  1000. if (oLeft instanceof cXSDayTimeDuration) {
  1001. if (oRight instanceof cXSDayTimeDuration)
  1002. sOperator = "dayTimeDuration-greater-than";
  1003. }
  1004. // Call operator function
  1005. if (sOperator)
  1006. return hStaticContext_operators[sOperator].call(oContext, oLeft, oRight);
  1007. // skipped: xs:anyURI (covered by xs:string)
  1008. throw new cException("XPTY0004"
  1009. ); // Cannot compare {type1} to {type2}
  1010. };
  1011. hComparisonExpr_ValueComp_operators['lt'] = function(oLeft, oRight, oContext) {
  1012. var sOperator = '';
  1013. if (fXSAnyAtomicType_isNumeric(oLeft)) {
  1014. if (fXSAnyAtomicType_isNumeric(oRight))
  1015. sOperator = "numeric-less-than";
  1016. }
  1017. else
  1018. if (oLeft instanceof cXSBoolean) {
  1019. if (oRight instanceof cXSBoolean)
  1020. sOperator = "boolean-less-than";
  1021. }
  1022. else
  1023. if (oLeft instanceof cXSString) {
  1024. if (oRight instanceof cXSString)
  1025. return hStaticContext_operators["numeric-less-than"].call(oContext, hStaticContext_functions["compare"].call(oContext, oLeft, oRight), new cXSInteger(0));
  1026. }
  1027. else
  1028. if (oLeft instanceof cXSDate) {
  1029. if (oRight instanceof cXSDate)
  1030. sOperator = "date-less-than";
  1031. }
  1032. else
  1033. if (oLeft instanceof cXSTime) {
  1034. if (oRight instanceof cXSTime)
  1035. sOperator = "time-less-than";
  1036. }
  1037. else
  1038. if (oLeft instanceof cXSDateTime) {
  1039. if (oRight instanceof cXSDateTime)
  1040. sOperator = "dateTime-less-than";
  1041. }
  1042. else
  1043. if (oLeft instanceof cXSYearMonthDuration) {
  1044. if (oRight instanceof cXSYearMonthDuration)
  1045. sOperator = "yearMonthDuration-less-than";
  1046. }
  1047. else
  1048. if (oLeft instanceof cXSDayTimeDuration) {
  1049. if (oRight instanceof cXSDayTimeDuration)
  1050. sOperator = "dayTimeDuration-less-than";
  1051. }
  1052. // Call operator function
  1053. if (sOperator)
  1054. return hStaticContext_operators[sOperator].call(oContext, oLeft, oRight);
  1055. // skipped: xs:anyURI (covered by xs:string)
  1056. throw new cException("XPTY0004"
  1057. ); // Cannot compare {type1} to {type2}
  1058. };
  1059. hComparisonExpr_ValueComp_operators['ge'] = function(oLeft, oRight, oContext) {
  1060. var sOperator = '';
  1061. if (fXSAnyAtomicType_isNumeric(oLeft)) {
  1062. if (fXSAnyAtomicType_isNumeric(oRight))
  1063. sOperator = "numeric-less-than";
  1064. }
  1065. else
  1066. if (oLeft instanceof cXSBoolean) {
  1067. if (oRight instanceof cXSBoolean)
  1068. sOperator = "boolean-less-than";
  1069. }
  1070. else
  1071. if (oLeft instanceof cXSString) {
  1072. if (oRight instanceof cXSString)
  1073. return hStaticContext_operators["numeric-greater-than"].call(oContext, hStaticContext_functions["compare"].call(oContext, oLeft, oRight), new cXSInteger(-1));
  1074. }
  1075. else
  1076. if (oLeft instanceof cXSDate) {
  1077. if (oRight instanceof cXSDate)
  1078. sOperator = "date-less-than";
  1079. }
  1080. else
  1081. if (oLeft instanceof cXSTime) {
  1082. if (oRight instanceof cXSTime)
  1083. sOperator = "time-less-than";
  1084. }
  1085. else
  1086. if (oLeft instanceof cXSDateTime) {
  1087. if (oRight instanceof cXSDateTime)
  1088. sOperator = "dateTime-less-than";
  1089. }
  1090. else
  1091. if (oLeft instanceof cXSYearMonthDuration) {
  1092. if (oRight instanceof cXSYearMonthDuration)
  1093. sOperator = "yearMonthDuration-less-than";
  1094. }
  1095. else
  1096. if (oLeft instanceof cXSDayTimeDuration) {
  1097. if (oRight instanceof cXSDayTimeDuration)
  1098. sOperator = "dayTimeDuration-less-than";
  1099. }
  1100. // Call operator function
  1101. if (sOperator)
  1102. return new cXSBoolean(!hStaticContext_operators[sOperator].call(oContext, oLeft, oRight).valueOf());
  1103. // skipped: xs:anyURI (covered by xs:string)
  1104. throw new cException("XPTY0004"
  1105. ); // Cannot compare {type1} to {type2}
  1106. };
  1107. hComparisonExpr_ValueComp_operators['le'] = function(oLeft, oRight, oContext) {
  1108. var sOperator = '';
  1109. if (fXSAnyAtomicType_isNumeric(oLeft)) {
  1110. if (fXSAnyAtomicType_isNumeric(oRight))
  1111. sOperator = "numeric-greater-than";
  1112. }
  1113. else
  1114. if (oLeft instanceof cXSBoolean) {
  1115. if (oRight instanceof cXSBoolean)
  1116. sOperator = "boolean-greater-than";
  1117. }
  1118. else
  1119. if (oLeft instanceof cXSString) {
  1120. if (oRight instanceof cXSString)
  1121. return hStaticContext_operators["numeric-less-than"].call(oContext, hStaticContext_functions["compare"].call(oContext, oLeft, oRight), new cXSInteger(1));
  1122. }
  1123. else
  1124. if (oLeft instanceof cXSDate) {
  1125. if (oRight instanceof cXSDate)
  1126. sOperator = "date-greater-than";
  1127. }
  1128. else
  1129. if (oLeft instanceof cXSTime) {
  1130. if (oRight instanceof cXSTime)
  1131. sOperator = "time-greater-than";
  1132. }
  1133. else
  1134. if (oLeft instanceof cXSDateTime) {
  1135. if (oRight instanceof cXSDateTime)
  1136. sOperator = "dateTime-greater-than";
  1137. }
  1138. else
  1139. if (oLeft instanceof cXSYearMonthDuration) {
  1140. if (oRight instanceof cXSYearMonthDuration)
  1141. sOperator = "yearMonthDuration-greater-than";
  1142. }
  1143. else
  1144. if (oLeft instanceof cXSDayTimeDuration) {
  1145. if (oRight instanceof cXSDayTimeDuration)
  1146. sOperator = "dayTimeDuration-greater-than";
  1147. }
  1148. // Call operator function
  1149. if (sOperator)
  1150. return new cXSBoolean(!hStaticContext_operators[sOperator].call(oContext, oLeft, oRight).valueOf());
  1151. // skipped: xs:anyURI (covered by xs:string)
  1152. throw new cException("XPTY0004"
  1153. ); // Cannot compare {type1} to {type2}
  1154. };
  1155. // Node comparison
  1156. function fComparisonExpr_NodeComp(oExpr, oContext) {
  1157. var oLeft = oExpr.left.evaluate(oContext);
  1158. if (!oLeft.length)
  1159. return null;
  1160. // Assert cardinality
  1161. fFunctionCall_assertSequenceCardinality(oContext, oLeft, '?'
  1162. );
  1163. // Assert item type
  1164. fFunctionCall_assertSequenceItemType(oContext, oLeft, cXTNode
  1165. );
  1166. var oRight = oExpr.right.evaluate(oContext);
  1167. if (!oRight.length)
  1168. return null;
  1169. // Assert cardinality
  1170. fFunctionCall_assertSequenceCardinality(oContext, oRight, '?'
  1171. );
  1172. // Assert item type
  1173. fFunctionCall_assertSequenceItemType(oContext, oRight, cXTNode
  1174. );
  1175. return hComparisonExpr_NodeComp_operators[oExpr.operator](oLeft[0], oRight[0], oContext);
  1176. };
  1177. var hComparisonExpr_NodeComp_operators = {};
  1178. hComparisonExpr_NodeComp_operators['is'] = function(oLeft, oRight, oContext) {
  1179. return hStaticContext_operators["is-same-node"].call(oContext, oLeft, oRight);
  1180. };
  1181. hComparisonExpr_NodeComp_operators['>>'] = function(oLeft, oRight, oContext) {
  1182. return hStaticContext_operators["node-after"].call(oContext, oLeft, oRight);
  1183. };
  1184. hComparisonExpr_NodeComp_operators['<<'] = function(oLeft, oRight, oContext) {
  1185. return hStaticContext_operators["node-before"].call(oContext, oLeft, oRight);
  1186. };
  1187. // Operators
  1188. var hComparisonExpr_operators = {
  1189. // GeneralComp
  1190. '=': fComparisonExpr_GeneralComp,
  1191. '!=': fComparisonExpr_GeneralComp,
  1192. '<': fComparisonExpr_GeneralComp,
  1193. '<=': fComparisonExpr_GeneralComp,
  1194. '>': fComparisonExpr_GeneralComp,
  1195. '>=': fComparisonExpr_GeneralComp,
  1196. // ValueComp
  1197. 'eq': fComparisonExpr_ValueComp,
  1198. 'ne': fComparisonExpr_ValueComp,
  1199. 'lt': fComparisonExpr_ValueComp,
  1200. 'le': fComparisonExpr_ValueComp,
  1201. 'gt': fComparisonExpr_ValueComp,
  1202. 'ge': fComparisonExpr_ValueComp,
  1203. // NodeComp
  1204. 'is': fComparisonExpr_NodeComp,
  1205. '>>': fComparisonExpr_NodeComp,
  1206. '<<': fComparisonExpr_NodeComp
  1207. };
  1208. /*
  1209. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  1210. *
  1211. * Copyright (c) 2012 Sergey Ilinsky
  1212. * Dual licensed under the MIT and GPL licenses.
  1213. *
  1214. *
  1215. */
  1216. function cAdditiveExpr(oExpr) {
  1217. this.left = oExpr;
  1218. this.items = [];
  1219. };
  1220. cAdditiveExpr.prototype.left = null;
  1221. cAdditiveExpr.prototype.items = null;
  1222. //
  1223. var hAdditiveExpr_operators = {};
  1224. hAdditiveExpr_operators['+'] = function(oLeft, oRight, oContext) {
  1225. var sOperator = '',
  1226. bReverse = false;
  1227. if (fXSAnyAtomicType_isNumeric(oLeft)) {
  1228. if (fXSAnyAtomicType_isNumeric(oRight))
  1229. sOperator = "numeric-add";
  1230. }
  1231. else
  1232. if (oLeft instanceof cXSDate) {
  1233. if (oRight instanceof cXSYearMonthDuration)
  1234. sOperator = "add-yearMonthDuration-to-date";
  1235. else
  1236. if (oRight instanceof cXSDayTimeDuration)
  1237. sOperator = "add-dayTimeDuration-to-date";
  1238. }
  1239. else
  1240. if (oLeft instanceof cXSYearMonthDuration) {
  1241. if (oRight instanceof cXSDate) {
  1242. sOperator = "add-yearMonthDuration-to-date";
  1243. bReverse = true;
  1244. }
  1245. else
  1246. if (oRight instanceof cXSDateTime) {
  1247. sOperator = "add-yearMonthDuration-to-dateTime";
  1248. bReverse = true;
  1249. }
  1250. else
  1251. if (oRight instanceof cXSYearMonthDuration)
  1252. sOperator = "add-yearMonthDurations";
  1253. }
  1254. else
  1255. if (oLeft instanceof cXSDayTimeDuration) {
  1256. if (oRight instanceof cXSDate) {
  1257. sOperator = "add-dayTimeDuration-to-date";
  1258. bReverse = true;
  1259. }
  1260. else
  1261. if (oRight instanceof cXSTime) {
  1262. sOperator = "add-dayTimeDuration-to-time";
  1263. bReverse = true;
  1264. }
  1265. else
  1266. if (oRight instanceof cXSDateTime) {
  1267. sOperator = "add-dayTimeDuration-to-dateTime";
  1268. bReverse = true;
  1269. }
  1270. else
  1271. if (oRight instanceof cXSDayTimeDuration)
  1272. sOperator = "add-dayTimeDurations";
  1273. }
  1274. else
  1275. if (oLeft instanceof cXSTime) {
  1276. if (oRight instanceof cXSDayTimeDuration)
  1277. sOperator = "add-dayTimeDuration-to-time";
  1278. }
  1279. else
  1280. if (oLeft instanceof cXSDateTime) {
  1281. if (oRight instanceof cXSYearMonthDuration)
  1282. sOperator = "add-yearMonthDuration-to-dateTime";
  1283. else
  1284. if (oRight instanceof cXSDayTimeDuration)
  1285. sOperator = "add-dayTimeDuration-to-dateTime";
  1286. }
  1287. // Call operator function
  1288. if (sOperator)
  1289. return hStaticContext_operators[sOperator].call(oContext, bReverse ? oRight : oLeft, bReverse ? oLeft : oRight);
  1290. //
  1291. throw new cException("XPTY0004"
  1292. ); // Arithmetic operator is not defined for arguments of types ({type1}, {type2})
  1293. };
  1294. hAdditiveExpr_operators['-'] = function (oLeft, oRight, oContext) {
  1295. var sOperator = '';
  1296. if (fXSAnyAtomicType_isNumeric(oLeft)) {
  1297. if (fXSAnyAtomicType_isNumeric(oRight))
  1298. sOperator = "numeric-subtract";
  1299. }
  1300. else
  1301. if (oLeft instanceof cXSDate) {
  1302. if (oRight instanceof cXSDate)
  1303. sOperator = "subtract-dates";
  1304. else
  1305. if (oRight instanceof cXSYearMonthDuration)
  1306. sOperator = "subtract-yearMonthDuration-from-date";
  1307. else
  1308. if (oRight instanceof cXSDayTimeDuration)
  1309. sOperator = "subtract-dayTimeDuration-from-date";
  1310. }
  1311. else
  1312. if (oLeft instanceof cXSTime) {
  1313. if (oRight instanceof cXSTime)
  1314. sOperator = "subtract-times";
  1315. else
  1316. if (oRight instanceof cXSDayTimeDuration)
  1317. sOperator = "subtract-dayTimeDuration-from-time";
  1318. }
  1319. else
  1320. if (oLeft instanceof cXSDateTime) {
  1321. if (oRight instanceof cXSDateTime)
  1322. sOperator = "subtract-dateTimes";
  1323. else
  1324. if (oRight instanceof cXSYearMonthDuration)
  1325. sOperator = "subtract-yearMonthDuration-from-dateTime";
  1326. else
  1327. if (oRight instanceof cXSDayTimeDuration)
  1328. sOperator = "subtract-dayTimeDuration-from-dateTime";
  1329. }
  1330. else
  1331. if (oLeft instanceof cXSYearMonthDuration) {
  1332. if (oRight instanceof cXSYearMonthDuration)
  1333. sOperator = "subtract-yearMonthDurations";
  1334. }
  1335. else
  1336. if (oLeft instanceof cXSDayTimeDuration) {
  1337. if (oRight instanceof cXSDayTimeDuration)
  1338. sOperator = "subtract-dayTimeDurations";
  1339. }
  1340. // Call operator function
  1341. if (sOperator)
  1342. return hStaticContext_operators[sOperator].call(oContext, oLeft, oRight);
  1343. //
  1344. throw new cException("XPTY0004"
  1345. ); // Arithmetic operator is not defined for arguments of types ({type1}, {type2})
  1346. };
  1347. // Static members
  1348. function fAdditiveExpr_parse (oLexer, oStaticContext) {
  1349. var oExpr;
  1350. if (oLexer.eof() ||!(oExpr = fMultiplicativeExpr_parse(oLexer, oStaticContext)))
  1351. return;
  1352. if (!(oLexer.peek() in hAdditiveExpr_operators))
  1353. return oExpr;
  1354. // Additive expression
  1355. var oAdditiveExpr = new cAdditiveExpr(oExpr),
  1356. sOperator;
  1357. while ((sOperator = oLexer.peek()) in hAdditiveExpr_operators) {
  1358. oLexer.next();
  1359. if (oLexer.eof() ||!(oExpr = fMultiplicativeExpr_parse(oLexer, oStaticContext)))
  1360. throw new cException("XPST0003"
  1361. );
  1362. oAdditiveExpr.items.push([sOperator, oExpr]);
  1363. }
  1364. return oAdditiveExpr;
  1365. };
  1366. // Public members
  1367. cAdditiveExpr.prototype.evaluate = function (oContext) {
  1368. var oLeft = fFunction_sequence_atomize(this.left.evaluate(oContext), oContext);
  1369. if (!oLeft.length)
  1370. return [];
  1371. // Assert cardinality
  1372. fFunctionCall_assertSequenceCardinality(oContext, oLeft, '?'
  1373. );
  1374. var vLeft = oLeft[0];
  1375. if (vLeft instanceof cXSUntypedAtomic)
  1376. vLeft = cXSDouble.cast(vLeft); // cast to xs:double
  1377. for (var nIndex = 0, nLength = this.items.length, oRight, vRight; nIndex < nLength; nIndex++) {
  1378. oRight = fFunction_sequence_atomize(this.items[nIndex][1].evaluate(oContext), oContext);
  1379. if (!oRight.length)
  1380. return [];
  1381. // Assert cardinality
  1382. fFunctionCall_assertSequenceCardinality(oContext, oRight, '?'
  1383. );
  1384. vRight = oRight[0];
  1385. if (vRight instanceof cXSUntypedAtomic)
  1386. vRight = cXSDouble.cast(vRight); // cast to xs:double
  1387. vLeft = hAdditiveExpr_operators[this.items[nIndex][0]](vLeft, vRight, oContext);
  1388. }
  1389. return [vLeft];
  1390. };
  1391. /*
  1392. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  1393. *
  1394. * Copyright (c) 2012 Sergey Ilinsky
  1395. * Dual licensed under the MIT and GPL licenses.
  1396. *
  1397. *
  1398. */
  1399. function cMultiplicativeExpr(oExpr) {
  1400. this.left = oExpr;
  1401. this.items = [];
  1402. };
  1403. cMultiplicativeExpr.prototype.left = null;
  1404. cMultiplicativeExpr.prototype.items = null;
  1405. //
  1406. var hMultiplicativeExpr_operators = {};
  1407. hMultiplicativeExpr_operators['*'] = function (oLeft, oRight, oContext) {
  1408. var sOperator = '',
  1409. bReverse = false;
  1410. if (fXSAnyAtomicType_isNumeric(oLeft)) {
  1411. if (fXSAnyAtomicType_isNumeric(oRight))
  1412. sOperator = "numeric-multiply";
  1413. else
  1414. if (oRight instanceof cXSYearMonthDuration) {
  1415. sOperator = "multiply-yearMonthDuration";
  1416. bReverse = true;
  1417. }
  1418. else
  1419. if (oRight instanceof cXSDayTimeDuration) {
  1420. sOperator = "multiply-dayTimeDuration";
  1421. bReverse = true;
  1422. }
  1423. }
  1424. else {
  1425. if (oLeft instanceof cXSYearMonthDuration) {
  1426. if (fXSAnyAtomicType_isNumeric(oRight))
  1427. sOperator = "multiply-yearMonthDuration";
  1428. }
  1429. else
  1430. if (oLeft instanceof cXSDayTimeDuration) {
  1431. if (fXSAnyAtomicType_isNumeric(oRight))
  1432. sOperator = "multiply-dayTimeDuration";
  1433. }
  1434. }
  1435. // Call operator function
  1436. if (sOperator)
  1437. return hStaticContext_operators[sOperator].call(oContext, bReverse ? oRight : oLeft, bReverse ? oLeft : oRight);
  1438. //
  1439. throw new cException("XPTY0004"
  1440. ); // Arithmetic operator is not defined for arguments of types ({type1}, {type2})
  1441. };
  1442. hMultiplicativeExpr_operators['div'] = function (oLeft, oRight, oContext) {
  1443. var sOperator = '';
  1444. if (fXSAnyAtomicType_isNumeric(oLeft)) {
  1445. if (fXSAnyAtomicType_isNumeric(oRight))
  1446. sOperator = "numeric-divide";
  1447. }
  1448. else
  1449. if (oLeft instanceof cXSYearMonthDuration) {
  1450. if (fXSAnyAtomicType_isNumeric(oRight))
  1451. sOperator = "divide-yearMonthDuration";
  1452. else
  1453. if (oRight instanceof cXSYearMonthDuration)
  1454. sOperator = "divide-yearMonthDuration-by-yearMonthDuration";
  1455. }
  1456. else
  1457. if (oLeft instanceof cXSDayTimeDuration) {
  1458. if (fXSAnyAtomicType_isNumeric(oRight))
  1459. sOperator = "divide-dayTimeDuration";
  1460. else
  1461. if (oRight instanceof cXSDayTimeDuration)
  1462. sOperator = "divide-dayTimeDuration-by-dayTimeDuration";
  1463. }
  1464. // Call operator function
  1465. if (sOperator)
  1466. return hStaticContext_operators[sOperator].call(oContext, oLeft, oRight);
  1467. //
  1468. throw new cException("XPTY0004"
  1469. ); // Arithmetic operator is not defined for arguments of types ({type1}, {type2})
  1470. };
  1471. hMultiplicativeExpr_operators['idiv'] = function (oLeft, oRight, oContext) {
  1472. if (fXSAnyAtomicType_isNumeric(oLeft) && fXSAnyAtomicType_isNumeric(oRight))
  1473. return hStaticContext_operators["numeric-integer-divide"].call(oContext, oLeft, oRight);
  1474. //
  1475. throw new cException("XPTY0004"
  1476. ); // Arithmetic operator is not defined for arguments of types ({type1}, {type2})
  1477. };
  1478. hMultiplicativeExpr_operators['mod'] = function (oLeft, oRight, oContext) {
  1479. if (fXSAnyAtomicType_isNumeric(oLeft) && fXSAnyAtomicType_isNumeric(oRight))
  1480. return hStaticContext_operators["numeric-mod"].call(oContext, oLeft, oRight);
  1481. //
  1482. throw new cException("XPTY0004"
  1483. ); // Arithmetic operator is not defined for arguments of types ({type1}, {type2})
  1484. };
  1485. // Static members
  1486. function fMultiplicativeExpr_parse (oLexer, oStaticContext) {
  1487. var oExpr;
  1488. if (oLexer.eof() ||!(oExpr = fUnionExpr_parse(oLexer, oStaticContext)))
  1489. return;
  1490. if (!(oLexer.peek() in hMultiplicativeExpr_operators))
  1491. return oExpr;
  1492. // Additive expression
  1493. var oMultiplicativeExpr = new cMultiplicativeExpr(oExpr),
  1494. sOperator;
  1495. while ((sOperator = oLexer.peek()) in hMultiplicativeExpr_operators) {
  1496. oLexer.next();
  1497. if (oLexer.eof() ||!(oExpr = fUnionExpr_parse(oLexer, oStaticContext)))
  1498. throw new cException("XPST0003"
  1499. );
  1500. oMultiplicativeExpr.items.push([sOperator, oExpr]);
  1501. }
  1502. return oMultiplicativeExpr;
  1503. };
  1504. // Public members
  1505. cMultiplicativeExpr.prototype.evaluate = function (oContext) {
  1506. var oLeft = fFunction_sequence_atomize(this.left.evaluate(oContext), oContext);
  1507. //
  1508. if (!oLeft.length)
  1509. return [];
  1510. // Assert cardinality
  1511. fFunctionCall_assertSequenceCardinality(oContext, oLeft, '?'
  1512. );
  1513. var vLeft = oLeft[0];
  1514. if (vLeft instanceof cXSUntypedAtomic)
  1515. vLeft = cXSDouble.cast(vLeft); // cast to xs:double
  1516. for (var nIndex = 0, nLength = this.items.length, oRight, vRight; nIndex < nLength; nIndex++) {
  1517. oRight = fFunction_sequence_atomize(this.items[nIndex][1].evaluate(oContext), oContext);
  1518. if (!oRight.length)
  1519. return [];
  1520. // Assert cardinality
  1521. fFunctionCall_assertSequenceCardinality(oContext, oRight, '?'
  1522. );
  1523. vRight = oRight[0];
  1524. if (vRight instanceof cXSUntypedAtomic)
  1525. vRight = cXSDouble.cast(vRight); // cast to xs:double
  1526. vLeft = hMultiplicativeExpr_operators[this.items[nIndex][0]](vLeft, vRight, oContext);
  1527. }
  1528. return [vLeft];
  1529. };
  1530. /*
  1531. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  1532. *
  1533. * Copyright (c) 2012 Sergey Ilinsky
  1534. * Dual licensed under the MIT and GPL licenses.
  1535. *
  1536. *
  1537. */
  1538. function cUnaryExpr(sOperator, oExpr) {
  1539. this.operator = sOperator;
  1540. this.expression = oExpr;
  1541. };
  1542. cUnaryExpr.prototype.operator = null;
  1543. cUnaryExpr.prototype.expression = null;
  1544. //
  1545. var hUnaryExpr_operators = {};
  1546. hUnaryExpr_operators['-'] = function(oRight, oContext) {
  1547. if (fXSAnyAtomicType_isNumeric(oRight))
  1548. return hStaticContext_operators["numeric-unary-minus"].call(oContext, oRight);
  1549. //
  1550. throw new cException("XPTY0004"
  1551. ); // Arithmetic operator is not defined for arguments of types ({type1}, {type2})
  1552. };
  1553. hUnaryExpr_operators['+'] = function(oRight, oContext) {
  1554. if (fXSAnyAtomicType_isNumeric(oRight))
  1555. return hStaticContext_operators["numeric-unary-plus"].call(oContext, oRight);
  1556. //
  1557. throw new cException("XPTY0004"
  1558. ); // Arithmetic operator is not defined for arguments of types ({type1}, {type2})
  1559. };
  1560. // Static members
  1561. // UnaryExpr := ("-" | "+")* ValueExpr
  1562. function fUnaryExpr_parse (oLexer, oStaticContext) {
  1563. if (oLexer.eof())
  1564. return;
  1565. if (!(oLexer.peek() in hUnaryExpr_operators))
  1566. return fValueExpr_parse(oLexer, oStaticContext);
  1567. // Unary expression
  1568. var sOperator = '+',
  1569. oExpr;
  1570. while (oLexer.peek() in hUnaryExpr_operators) {
  1571. if (oLexer.peek() == '-')
  1572. sOperator = sOperator == '-' ? '+' : '-';
  1573. oLexer.next();
  1574. }
  1575. if (oLexer.eof() ||!(oExpr = fValueExpr_parse(oLexer, oStaticContext)))
  1576. throw new cException("XPST0003"
  1577. );
  1578. return new cUnaryExpr(sOperator, oExpr);
  1579. };
  1580. cUnaryExpr.prototype.evaluate = function (oContext) {
  1581. var oRight = fFunction_sequence_atomize(this.expression.evaluate(oContext), oContext);
  1582. //
  1583. if (!oRight.length)
  1584. return [];
  1585. // Assert cardinality
  1586. fFunctionCall_assertSequenceCardinality(oContext, oRight, '?'
  1587. );
  1588. var vRight = oRight[0];
  1589. if (vRight instanceof cXSUntypedAtomic)
  1590. vRight = cXSDouble.cast(vRight); // cast to xs:double
  1591. return [hUnaryExpr_operators[this.operator](vRight, oContext)];
  1592. };
  1593. /*
  1594. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  1595. *
  1596. * Copyright (c) 2012 Sergey Ilinsky
  1597. * Dual licensed under the MIT and GPL licenses.
  1598. *
  1599. *
  1600. */
  1601. function cValueExpr() {
  1602. };
  1603. // Static members
  1604. function fValueExpr_parse (oLexer, oStaticContext) {
  1605. return fPathExpr_parse(oLexer, oStaticContext);
  1606. };
  1607. /*
  1608. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  1609. *
  1610. * Copyright (c) 2012 Sergey Ilinsky
  1611. * Dual licensed under the MIT and GPL licenses.
  1612. *
  1613. *
  1614. */
  1615. function cOrExpr(oExpr) {
  1616. this.left = oExpr;
  1617. this.items = [];
  1618. };
  1619. cOrExpr.prototype.left = null;
  1620. cOrExpr.prototype.items = null;
  1621. // Static members
  1622. function fOrExpr_parse (oLexer, oStaticContext) {
  1623. var oExpr;
  1624. if (oLexer.eof() ||!(oExpr = fAndExpr_parse(oLexer, oStaticContext)))
  1625. return;
  1626. if (oLexer.peek() != "or")
  1627. return oExpr;
  1628. // Or expression
  1629. var oOrExpr = new cOrExpr(oExpr);
  1630. while (oLexer.peek() == "or") {
  1631. oLexer.next();
  1632. if (oLexer.eof() ||!(oExpr = fAndExpr_parse(oLexer, oStaticContext)))
  1633. throw new cException("XPST0003"
  1634. );
  1635. oOrExpr.items.push(oExpr);
  1636. }
  1637. return oOrExpr;
  1638. };
  1639. // Public members
  1640. cOrExpr.prototype.evaluate = function (oContext) {
  1641. var bValue = fFunction_sequence_toEBV(this.left.evaluate(oContext), oContext);
  1642. for (var nIndex = 0, nLength = this.items.length; (nIndex < nLength) && !bValue; nIndex++)
  1643. bValue = fFunction_sequence_toEBV(this.items[nIndex].evaluate(oContext), oContext);
  1644. return [new cXSBoolean(bValue)];
  1645. };
  1646. /*
  1647. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  1648. *
  1649. * Copyright (c) 2012 Sergey Ilinsky
  1650. * Dual licensed under the MIT and GPL licenses.
  1651. *
  1652. *
  1653. */
  1654. function cAndExpr(oExpr) {
  1655. this.left = oExpr;
  1656. this.items = [];
  1657. };
  1658. cAndExpr.prototype.left = null;
  1659. cAndExpr.prototype.items = null;
  1660. // Static members
  1661. function fAndExpr_parse (oLexer, oStaticContext) {
  1662. var oExpr;
  1663. if (oLexer.eof() ||!(oExpr = fComparisonExpr_parse(oLexer, oStaticContext)))
  1664. return;
  1665. if (oLexer.peek() != "and")
  1666. return oExpr;
  1667. // And expression
  1668. var oAndExpr = new cAndExpr(oExpr);
  1669. while (oLexer.peek() == "and") {
  1670. oLexer.next();
  1671. if (oLexer.eof() ||!(oExpr = fComparisonExpr_parse(oLexer, oStaticContext)))
  1672. throw new cException("XPST0003"
  1673. );
  1674. oAndExpr.items.push(oExpr);
  1675. }
  1676. return oAndExpr;
  1677. };
  1678. // Public members
  1679. cAndExpr.prototype.evaluate = function (oContext) {
  1680. var bValue = fFunction_sequence_toEBV(this.left.evaluate(oContext), oContext);
  1681. for (var nIndex = 0, nLength = this.items.length; (nIndex < nLength) && bValue; nIndex++)
  1682. bValue = fFunction_sequence_toEBV(this.items[nIndex].evaluate(oContext), oContext);
  1683. return [new cXSBoolean(bValue)];
  1684. };
  1685. /*
  1686. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  1687. *
  1688. * Copyright (c) 2012 Sergey Ilinsky
  1689. * Dual licensed under the MIT and GPL licenses.
  1690. *
  1691. *
  1692. */
  1693. function cStepExpr() {
  1694. };
  1695. cStepExpr.prototype.predicates = null;
  1696. // Static members
  1697. function fStepExpr_parse (oLexer, oStaticContext) {
  1698. if (!oLexer.eof())
  1699. return fFilterExpr_parse(oLexer, oStaticContext)
  1700. || fAxisStep_parse(oLexer, oStaticContext);
  1701. };
  1702. function fStepExpr_parsePredicates (oLexer, oStaticContext, oStep) {
  1703. var oExpr;
  1704. // Parse predicates
  1705. while (oLexer.peek() == '[') {
  1706. oLexer.next();
  1707. if (oLexer.eof() ||!(oExpr = fExpr_parse(oLexer, oStaticContext)))
  1708. throw new cException("XPST0003"
  1709. );
  1710. oStep.predicates.push(oExpr);
  1711. if (oLexer.peek() != ']')
  1712. throw new cException("XPST0003"
  1713. );
  1714. oLexer.next();
  1715. }
  1716. };
  1717. // Public members
  1718. cStepExpr.prototype.applyPredicates = function(oSequence, oContext) {
  1719. var vContextItem = oContext.item,
  1720. nContextPosition= oContext.position,
  1721. nContextSize = oContext.size;
  1722. //
  1723. for (var nPredicateIndex = 0, oSequence1, nPredicateLength = this.predicates.length; nPredicateIndex < nPredicateLength; nPredicateIndex++) {
  1724. oSequence1 = oSequence;
  1725. oSequence = [];
  1726. for (var nIndex = 0, oSequence2, nLength = oSequence1.length; nIndex < nLength; nIndex++) {
  1727. // Set new context
  1728. oContext.item = oSequence1[nIndex];
  1729. oContext.position = nIndex + 1;
  1730. oContext.size = nLength;
  1731. //
  1732. oSequence2 = this.predicates[nPredicateIndex].evaluate(oContext);
  1733. //
  1734. if (oSequence2.length == 1 && fXSAnyAtomicType_isNumeric(oSequence2[0])) {
  1735. if (oSequence2[0].valueOf() == nIndex + 1)
  1736. oSequence.push(oSequence1[nIndex]);
  1737. }
  1738. else
  1739. if (fFunction_sequence_toEBV(oSequence2, oContext))
  1740. oSequence.push(oSequence1[nIndex]);
  1741. }
  1742. }
  1743. // Restore context
  1744. oContext.item = vContextItem;
  1745. oContext.position = nContextPosition;
  1746. oContext.size = nContextSize;
  1747. //
  1748. return oSequence;
  1749. };
  1750. /*
  1751. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  1752. *
  1753. * Copyright (c) 2012 Sergey Ilinsky
  1754. * Dual licensed under the MIT and GPL licenses.
  1755. *
  1756. *
  1757. */
  1758. function cAxisStep(sAxis, oTest) {
  1759. this.axis = sAxis;
  1760. this.test = oTest;
  1761. this.predicates = [];
  1762. };
  1763. cAxisStep.prototype = new cStepExpr;
  1764. cAxisStep.prototype.axis = null;
  1765. cAxisStep.prototype.test = null;
  1766. //
  1767. var hAxisStep_axises = {};
  1768. // Forward axis
  1769. hAxisStep_axises["attribute"] = {};
  1770. hAxisStep_axises["child"] = {};
  1771. hAxisStep_axises["descendant"] = {};
  1772. hAxisStep_axises["descendant-or-self"] = {};
  1773. hAxisStep_axises["following"] = {};
  1774. hAxisStep_axises["following-sibling"] = {};
  1775. hAxisStep_axises["self"] = {};
  1776. // hAxisStep_axises["namespace"] = {}; // deprecated in 2.0
  1777. // Reverse axis
  1778. hAxisStep_axises["ancestor"] = {};
  1779. hAxisStep_axises["ancestor-or-self"] = {};
  1780. hAxisStep_axises["parent"] = {};
  1781. hAxisStep_axises["preceding"] = {};
  1782. hAxisStep_axises["preceding-sibling"] = {};
  1783. // Static members
  1784. function fAxisStep_parse (oLexer, oStaticContext) {
  1785. var sAxis = oLexer.peek(),
  1786. oExpr,
  1787. oStep;
  1788. if (oLexer.peek(1) == '::') {
  1789. if (!(sAxis in hAxisStep_axises))
  1790. throw new cException("XPST0003"
  1791. );
  1792. oLexer.next(2);
  1793. if (oLexer.eof() ||!(oExpr = fNodeTest_parse(oLexer, oStaticContext)))
  1794. throw new cException("XPST0003"
  1795. );
  1796. //
  1797. oStep = new cAxisStep(sAxis, oExpr);
  1798. }
  1799. else
  1800. if (sAxis == '..') {
  1801. oLexer.next();
  1802. oStep = new cAxisStep("parent", new cKindTest("node"));
  1803. }
  1804. else
  1805. if (sAxis == '@') {
  1806. oLexer.next();
  1807. if (oLexer.eof() ||!(oExpr = fNodeTest_parse(oLexer, oStaticContext)))
  1808. throw new cException("XPST0003"
  1809. );
  1810. //
  1811. oStep = new cAxisStep("attribute", oExpr);
  1812. }
  1813. else {
  1814. if (oLexer.eof() ||!(oExpr = fNodeTest_parse(oLexer, oStaticContext)))
  1815. return;
  1816. oStep = new cAxisStep(oExpr instanceof cKindTest && oExpr.name == "attribute" ? "attribute" : "child", oExpr);
  1817. }
  1818. //
  1819. fStepExpr_parsePredicates(oLexer, oStaticContext, oStep);
  1820. return oStep;
  1821. };
  1822. // Public members
  1823. cAxisStep.prototype.evaluate = function (oContext) {
  1824. var oItem = oContext.item;
  1825. if (!oContext.DOMAdapter.isNode(oItem))
  1826. throw new cException("XPTY0020");
  1827. var oSequence = [],
  1828. fGetProperty= oContext.DOMAdapter.getProperty,
  1829. nType = fGetProperty(oItem, "nodeType");
  1830. switch (this.axis) {
  1831. // Forward axis
  1832. case "attribute":
  1833. if (nType == 1)
  1834. for (var aAttributes = fGetProperty(oItem, "attributes"), nIndex = 0, nLength = aAttributes.length; nIndex < nLength; nIndex++)
  1835. oSequence.push(aAttributes[nIndex]);
  1836. break;
  1837. case "child":
  1838. for (var oNode = fGetProperty(oItem, "firstChild"); oNode; oNode = fGetProperty(oNode, "nextSibling"))
  1839. oSequence.push(oNode);
  1840. break;
  1841. case "descendant-or-self":
  1842. oSequence.push(oItem);
  1843. // No break left intentionally
  1844. case "descendant":
  1845. fAxisStep_getChildrenForward(fGetProperty(oItem, "firstChild"), oSequence, fGetProperty);
  1846. break;
  1847. case "following":
  1848. // TODO: Attribute node context
  1849. for (var oParent = oItem, oSibling; oParent; oParent = fGetProperty(oParent, "parentNode"))
  1850. if (oSibling = fGetProperty(oParent, "nextSibling"))
  1851. fAxisStep_getChildrenForward(oSibling, oSequence, fGetProperty);
  1852. break;
  1853. case "following-sibling":
  1854. for (var oNode = oItem; oNode = fGetProperty(oNode, "nextSibling");)
  1855. oSequence.push(oNode);
  1856. break;
  1857. case "self":
  1858. oSequence.push(oItem);
  1859. break;
  1860. // Reverse axis
  1861. case "ancestor-or-self":
  1862. oSequence.push(oItem);
  1863. // No break left intentionally
  1864. case "ancestor":
  1865. for (var oNode = nType == 2 ? fGetProperty(oItem, "ownerElement") : oItem; oNode = fGetProperty(oNode, "parentNode");)
  1866. oSequence.push(oNode);
  1867. break;
  1868. case "parent":
  1869. var oParent = nType == 2 ? fGetProperty(oItem, "ownerElement") : fGetProperty(oItem, "parentNode");
  1870. if (oParent)
  1871. oSequence.push(oParent);
  1872. break;
  1873. case "preceding":
  1874. // TODO: Attribute node context
  1875. for (var oParent = oItem, oSibling; oParent; oParent = fGetProperty(oParent, "parentNode"))
  1876. if (oSibling = fGetProperty(oParent, "previousSibling"))
  1877. fAxisStep_getChildrenBackward(oSibling, oSequence, fGetProperty);
  1878. break;
  1879. case "preceding-sibling":
  1880. for (var oNode = oItem; oNode = fGetProperty(oNode, "previousSibling");)
  1881. oSequence.push(oNode);
  1882. break;
  1883. }
  1884. // Apply test
  1885. if (oSequence.length && !(this.test instanceof cKindTest && this.test.name == "node")) {
  1886. var oSequence1 = oSequence;
  1887. oSequence = [];
  1888. for (var nIndex = 0, nLength = oSequence1.length; nIndex < nLength; nIndex++) {
  1889. if (this.test.test(oSequence1[nIndex], oContext))
  1890. oSequence.push(oSequence1[nIndex]);
  1891. }
  1892. }
  1893. // Apply predicates
  1894. if (oSequence.length && this.predicates.length)
  1895. oSequence = this.applyPredicates(oSequence, oContext);
  1896. // Reverse results if reverse axis
  1897. switch (this.axis) {
  1898. case "ancestor":
  1899. case "ancestor-or-self":
  1900. case "parent":
  1901. case "preceding":
  1902. case "preceding-sibling":
  1903. oSequence.reverse();
  1904. }
  1905. return oSequence;
  1906. };
  1907. //
  1908. function fAxisStep_getChildrenForward(oNode, oSequence, fGetProperty) {
  1909. for (var oChild; oNode; oNode = fGetProperty(oNode, "nextSibling")) {
  1910. oSequence.push(oNode);
  1911. if (oChild = fGetProperty(oNode, "firstChild"))
  1912. fAxisStep_getChildrenForward(oChild, oSequence, fGetProperty);
  1913. }
  1914. };
  1915. function fAxisStep_getChildrenBackward(oNode, oSequence, fGetProperty) {
  1916. for (var oChild; oNode; oNode = fGetProperty(oNode, "previousSibling")) {
  1917. if (oChild = fGetProperty(oNode, "lastChild"))
  1918. fAxisStep_getChildrenBackward(oChild, oSequence, fGetProperty);
  1919. oSequence.push(oNode);
  1920. }
  1921. };
  1922. /*
  1923. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  1924. *
  1925. * Copyright (c) 2012 Sergey Ilinsky
  1926. * Dual licensed under the MIT and GPL licenses.
  1927. *
  1928. *
  1929. */
  1930. function cPathExpr() {
  1931. this.items = [];
  1932. };
  1933. cPathExpr.prototype.items = null;
  1934. // Static members
  1935. function fPathExpr_parse (oLexer, oStaticContext) {
  1936. if (oLexer.eof())
  1937. return;
  1938. var sSingleSlash = '/',
  1939. sDoubleSlash = '/' + '/';
  1940. var oPathExpr = new cPathExpr(),
  1941. sSlash = oLexer.peek(),
  1942. oExpr;
  1943. // Parse first step
  1944. if (sSlash == sDoubleSlash || sSlash == sSingleSlash) {
  1945. oLexer.next();
  1946. oPathExpr.items.push(new cFunctionCall(null, "root", sNS_XPF));
  1947. //
  1948. if (sSlash == sDoubleSlash)
  1949. oPathExpr.items.push(new cAxisStep("descendant-or-self", new cKindTest("node")));
  1950. }
  1951. //
  1952. if (oLexer.eof() ||!(oExpr = fStepExpr_parse(oLexer, oStaticContext))) {
  1953. if (sSlash == sSingleSlash)
  1954. return oPathExpr.items[0]; // '/' expression
  1955. if (sSlash == sDoubleSlash)
  1956. throw new cException("XPST0003"
  1957. );
  1958. return;
  1959. }
  1960. oPathExpr.items.push(oExpr);
  1961. // Parse other steps
  1962. while ((sSlash = oLexer.peek()) == sSingleSlash || sSlash == sDoubleSlash) {
  1963. if (sSlash == sDoubleSlash)
  1964. oPathExpr.items.push(new cAxisStep("descendant-or-self", new cKindTest("node")));
  1965. //
  1966. oLexer.next();
  1967. if (oLexer.eof() ||!(oExpr = fStepExpr_parse(oLexer, oStaticContext)))
  1968. throw new cException("XPST0003"
  1969. );
  1970. //
  1971. oPathExpr.items.push(oExpr);
  1972. }
  1973. if (oPathExpr.items.length == 1)
  1974. return oPathExpr.items[0];
  1975. //
  1976. return oPathExpr;
  1977. };
  1978. // Public members
  1979. cPathExpr.prototype.evaluate = function (oContext) {
  1980. var vContextItem = oContext.item;
  1981. //
  1982. var oSequence = [vContextItem];
  1983. for (var nItemIndex = 0, nItemLength = this.items.length, oSequence1; nItemIndex < nItemLength; nItemIndex++) {
  1984. oSequence1 = [];
  1985. for (var nIndex = 0, nLength = oSequence.length; nIndex < nLength; nIndex++) {
  1986. // Set new context item
  1987. oContext.item = oSequence[nIndex];
  1988. //
  1989. for (var nRightIndex = 0, oSequence2 = this.items[nItemIndex].evaluate(oContext), nRightLength = oSequence2.length; nRightIndex < nRightLength; nRightIndex++)
  1990. if ((nItemIndex < nItemLength - 1) && !oContext.DOMAdapter.isNode(oSequence2[nRightIndex]))
  1991. throw new cException("XPTY0019");
  1992. else
  1993. if (fArray_indexOf(oSequence1, oSequence2[nRightIndex]) ==-1)
  1994. oSequence1.push(oSequence2[nRightIndex]);
  1995. }
  1996. oSequence = oSequence1;
  1997. };
  1998. // Restore context item
  1999. oContext.item = vContextItem;
  2000. //
  2001. return fFunction_sequence_order(oSequence, oContext);
  2002. };
  2003. /*
  2004. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2005. *
  2006. * Copyright (c) 2012 Sergey Ilinsky
  2007. * Dual licensed under the MIT and GPL licenses.
  2008. *
  2009. *
  2010. */
  2011. function cNodeTest() {
  2012. };
  2013. // Static members
  2014. function fNodeTest_parse (oLexer, oStaticContext) {
  2015. if (!oLexer.eof())
  2016. return fKindTest_parse(oLexer, oStaticContext)
  2017. || fNameTest_parse(oLexer, oStaticContext);
  2018. };
  2019. /*
  2020. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2021. *
  2022. * Copyright (c) 2012 Sergey Ilinsky
  2023. * Dual licensed under the MIT and GPL licenses.
  2024. *
  2025. *
  2026. */
  2027. function cKindTest(sName) {
  2028. this.name = sName;
  2029. this.args = [];
  2030. };
  2031. cKindTest.prototype = new cNodeTest;
  2032. cKindTest.prototype.name = null;
  2033. cKindTest.prototype.args = null;
  2034. var hKindTest_names = {};
  2035. //
  2036. hKindTest_names["document-node"] = {};
  2037. hKindTest_names["element"] = {};
  2038. hKindTest_names["attribute"] = {};
  2039. hKindTest_names["processing-instruction"] = {};
  2040. hKindTest_names["comment"] = {};
  2041. hKindTest_names["text"] = {};
  2042. hKindTest_names["node"] = {};
  2043. //
  2044. hKindTest_names["schema-element"] = {};
  2045. hKindTest_names["schema-attribute"] = {};
  2046. // Static members
  2047. function fKindTest_parse (oLexer, oStaticContext) {
  2048. var sName = oLexer.peek(),
  2049. oValue;
  2050. if (oLexer.peek(1) == '(') {
  2051. //
  2052. if (!(sName in hKindTest_names))
  2053. throw new cException("XPST0003"
  2054. );
  2055. //
  2056. oLexer.next(2);
  2057. //
  2058. var oTest = new cKindTest(sName);
  2059. if (oLexer.peek() != ')') {
  2060. if (sName == "document-node") {
  2061. // TODO: parse test further
  2062. }
  2063. else
  2064. if (sName == "element") {
  2065. // TODO: parse test further
  2066. }
  2067. else
  2068. if (sName == "attribute") {
  2069. // TODO: parse test further
  2070. }
  2071. else
  2072. if (sName == "processing-instruction") {
  2073. oValue = fStringLiteral_parse(oLexer, oStaticContext);
  2074. if (!oValue) {
  2075. oValue = new cStringLiteral(new cXSString(oLexer.peek()));
  2076. oLexer.next();
  2077. }
  2078. oTest.args.push(oValue);
  2079. }
  2080. else
  2081. if (sName == "schema-attribute") {
  2082. // TODO: parse test further
  2083. }
  2084. else
  2085. if (sName == "schema-element") {
  2086. // TODO: parse test further
  2087. }
  2088. }
  2089. else {
  2090. if (sName == "schema-attribute")
  2091. throw new cException("XPST0003"
  2092. );
  2093. else
  2094. if (sName == "schema-element")
  2095. throw new cException("XPST0003"
  2096. );
  2097. }
  2098. if (oLexer.peek() != ')')
  2099. throw new cException("XPST0003"
  2100. );
  2101. oLexer.next();
  2102. return oTest;
  2103. }
  2104. };
  2105. // Public members
  2106. cKindTest.prototype.test = function (oNode, oContext) {
  2107. var fGetProperty = oContext.DOMAdapter.getProperty,
  2108. nType = oContext.DOMAdapter.isNode(oNode) ? fGetProperty(oNode, "nodeType") : 0,
  2109. sTarget;
  2110. switch (this.name) {
  2111. // Node type test
  2112. case "node": return !!nType;
  2113. case "attribute": if (nType != 2) return false; break;
  2114. case "document-node": return nType == 9;
  2115. case "element": return nType == 1;
  2116. case "processing-instruction": if (nType != 7) return false; break;
  2117. case "comment": return nType == 8;
  2118. case "text": return nType == 3 || nType == 4;
  2119. // Schema tests
  2120. case "schema-attribute":
  2121. throw "KindTest '" + "schema-attribute" + "' not implemented";
  2122. case "schema-element":
  2123. throw "KindTest '" + "schema-element" + "' not implemented";
  2124. }
  2125. // Additional tests
  2126. if (nType == 2)
  2127. return fGetProperty(oNode, "prefix") != "xmlns" && fGetProperty(oNode, "localName") != "xmlns";
  2128. if (nType == 7) {
  2129. sTarget = fGetProperty(oNode, "target");
  2130. return this.args.length ? sTarget == this.args[0].value : sTarget != "xml";
  2131. }
  2132. return true;
  2133. };
  2134. /*
  2135. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2136. *
  2137. * Copyright (c) 2012 Sergey Ilinsky
  2138. * Dual licensed under the MIT and GPL licenses.
  2139. *
  2140. *
  2141. */
  2142. function cNameTest(sPrefix, sLocalName, sNameSpaceURI) {
  2143. this.prefix = sPrefix;
  2144. this.localName = sLocalName;
  2145. this.namespaceURI = sNameSpaceURI;
  2146. };
  2147. cNameTest.prototype = new cNodeTest;
  2148. cNameTest.prototype.prefix = null;
  2149. cNameTest.prototype.localName = null;
  2150. cNameTest.prototype.namespaceURI = null;
  2151. // Static members
  2152. var rNameTest = /^(?:(?![0-9-])(\w[\w.-]*|\*)\:)?(?![0-9-])(\w[\w.-]*|\*)$/;
  2153. function fNameTest_parse (oLexer, oStaticContext) {
  2154. var aMatch = oLexer.peek().match(rNameTest);
  2155. if (aMatch) {
  2156. if (aMatch[1] == '*' && aMatch[2] == '*')
  2157. throw new cException("XPST0003"
  2158. );
  2159. oLexer.next();
  2160. return new cNameTest(aMatch[1] || null, aMatch[2], aMatch[1] ? aMatch[1] == '*' ? '*' : oStaticContext.getURIForPrefix(aMatch[1]) || null : oStaticContext.defaultElementNamespace);
  2161. }
  2162. };
  2163. // Public members
  2164. cNameTest.prototype.test = function (oNode, oContext) {
  2165. var fGetProperty = oContext.DOMAdapter.getProperty,
  2166. nType = fGetProperty(oNode, "nodeType");
  2167. if (nType == 1 || nType == 2) {
  2168. if (this.localName == '*')
  2169. return (nType == 1 || (fGetProperty(oNode, "prefix") != "xmlns" && fGetProperty(oNode, "localName") != "xmlns")) && (!this.prefix || fGetProperty(oNode, "namespaceURI") == this.namespaceURI);
  2170. if (this.localName == fGetProperty(oNode, "localName"))
  2171. return this.namespaceURI == '*' || (nType == 2 && !this.prefix && !fGetProperty(oNode, "prefix")) || fGetProperty(oNode, "namespaceURI") == this.namespaceURI;
  2172. }
  2173. //
  2174. return false;
  2175. };
  2176. /*
  2177. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2178. *
  2179. * Copyright (c) 2012 Sergey Ilinsky
  2180. * Dual licensed under the MIT and GPL licenses.
  2181. *
  2182. *
  2183. */
  2184. function cPrimaryExpr() {
  2185. };
  2186. // Static members
  2187. function fPrimaryExpr_parse (oLexer, oStaticContext) {
  2188. if (!oLexer.eof())
  2189. return fContextItemExpr_parse(oLexer, oStaticContext)
  2190. || fParenthesizedExpr_parse(oLexer, oStaticContext)
  2191. || fFunctionCall_parse(oLexer, oStaticContext)
  2192. || fVarRef_parse(oLexer, oStaticContext)
  2193. || fLiteral_parse(oLexer, oStaticContext);
  2194. };
  2195. /*
  2196. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2197. *
  2198. * Copyright (c) 2012 Sergey Ilinsky
  2199. * Dual licensed under the MIT and GPL licenses.
  2200. *
  2201. *
  2202. */
  2203. function cParenthesizedExpr(oExpr) {
  2204. this.expression = oExpr;
  2205. };
  2206. // Static members
  2207. function fParenthesizedExpr_parse (oLexer, oStaticContext) {
  2208. if (oLexer.peek() == '(') {
  2209. oLexer.next();
  2210. // Check if not empty (allowed)
  2211. var oExpr = null;
  2212. if (oLexer.peek() != ')')
  2213. oExpr = fExpr_parse(oLexer, oStaticContext);
  2214. //
  2215. if (oLexer.peek() != ')')
  2216. throw new cException("XPST0003"
  2217. );
  2218. oLexer.next();
  2219. //
  2220. return new cParenthesizedExpr(oExpr);
  2221. }
  2222. };
  2223. // Public members
  2224. cParenthesizedExpr.prototype.evaluate = function (oContext) {
  2225. return this.expression ? this.expression.evaluate(oContext) : [];
  2226. };
  2227. /*
  2228. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2229. *
  2230. * Copyright (c) 2012 Sergey Ilinsky
  2231. * Dual licensed under the MIT and GPL licenses.
  2232. *
  2233. *
  2234. */
  2235. function cContextItemExpr() {
  2236. };
  2237. // Static members
  2238. function fContextItemExpr_parse (oLexer, oStaticContext) {
  2239. if (oLexer.peek() == '.') {
  2240. oLexer.next();
  2241. return new cContextItemExpr;
  2242. }
  2243. };
  2244. // Public members
  2245. cContextItemExpr.prototype.evaluate = function (oContext) {
  2246. if (oContext.item == null)
  2247. throw new cException("XPDY0002"
  2248. );
  2249. //
  2250. return [oContext.item];
  2251. };
  2252. /*
  2253. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2254. *
  2255. * Copyright (c) 2012 Sergey Ilinsky
  2256. * Dual licensed under the MIT and GPL licenses.
  2257. *
  2258. *
  2259. */
  2260. function cLiteral() {
  2261. };
  2262. cLiteral.prototype.value = null;
  2263. // Static members
  2264. function fLiteral_parse (oLexer, oStaticContext) {
  2265. if (!oLexer.eof())
  2266. return fNumericLiteral_parse(oLexer, oStaticContext)
  2267. || fStringLiteral_parse(oLexer, oStaticContext);
  2268. };
  2269. // Public members
  2270. cLiteral.prototype.evaluate = function (oContext) {
  2271. return [this.value];
  2272. };
  2273. /*
  2274. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2275. *
  2276. * Copyright (c) 2012 Sergey Ilinsky
  2277. * Dual licensed under the MIT and GPL licenses.
  2278. *
  2279. *
  2280. */
  2281. function cNumericLiteral(oValue) {
  2282. this.value = oValue;
  2283. };
  2284. cNumericLiteral.prototype = new cLiteral;
  2285. // Integer | Decimal | Double
  2286. var rNumericLiteral = /^[+\-]?(?:(?:(\d+)(?:\.(\d*))?)|(?:\.(\d+)))(?:[eE]([+-])?(\d+))?$/;
  2287. function fNumericLiteral_parse (oLexer, oStaticContext) {
  2288. var sValue = oLexer.peek(),
  2289. vValue = fNumericLiteral_parseValue(sValue);
  2290. if (vValue) {
  2291. oLexer.next();
  2292. return new cNumericLiteral(vValue);
  2293. }
  2294. };
  2295. function fNumericLiteral_parseValue(sValue) {
  2296. var aMatch = sValue.match(rNumericLiteral);
  2297. if (aMatch) {
  2298. var cType = cXSInteger;
  2299. if (aMatch[5])
  2300. cType = cXSDouble;
  2301. else
  2302. if (aMatch[2] || aMatch[3])
  2303. cType = cXSDecimal;
  2304. return new cType(+sValue);
  2305. }
  2306. };
  2307. /*
  2308. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2309. *
  2310. * Copyright (c) 2012 Sergey Ilinsky
  2311. * Dual licensed under the MIT and GPL licenses.
  2312. *
  2313. *
  2314. */
  2315. function cStringLiteral(oValue) {
  2316. this.value = oValue;
  2317. };
  2318. cStringLiteral.prototype = new cLiteral;
  2319. var rStringLiteral = /^'([^']*(?:''[^']*)*)'|"([^"]*(?:""[^"]*)*)"$/;
  2320. function fStringLiteral_parse (oLexer, oStaticContext) {
  2321. var aMatch = oLexer.peek().match(rStringLiteral);
  2322. if (aMatch) {
  2323. oLexer.next();
  2324. return new cStringLiteral(new cXSString(aMatch[1] ? aMatch[1].replace("''", "'") : aMatch[2] ? aMatch[2].replace('""', '"') : ''));
  2325. }
  2326. };
  2327. /*
  2328. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2329. *
  2330. * Copyright (c) 2012 Sergey Ilinsky
  2331. * Dual licensed under the MIT and GPL licenses.
  2332. *
  2333. *
  2334. */
  2335. function cFilterExpr(oPrimary) {
  2336. this.expression = oPrimary;
  2337. this.predicates = [];
  2338. };
  2339. cFilterExpr.prototype = new cStepExpr;
  2340. cFilterExpr.prototype.expression = null;
  2341. // Static members
  2342. function fFilterExpr_parse (oLexer, oStaticContext) {
  2343. var oExpr;
  2344. if (oLexer.eof() ||!(oExpr = fPrimaryExpr_parse(oLexer, oStaticContext)))
  2345. return;
  2346. var oFilterExpr = new cFilterExpr(oExpr);
  2347. // Parse predicates
  2348. fStepExpr_parsePredicates(oLexer, oStaticContext, oFilterExpr);
  2349. // If no predicates found
  2350. if (oFilterExpr.predicates.length == 0)
  2351. return oFilterExpr.expression;
  2352. return oFilterExpr;
  2353. };
  2354. // Public members
  2355. cFilterExpr.prototype.evaluate = function (oContext) {
  2356. var oSequence = this.expression.evaluate(oContext);
  2357. if (this.predicates.length && oSequence.length)
  2358. oSequence = this.applyPredicates(oSequence, oContext);
  2359. return oSequence;
  2360. };
  2361. /*
  2362. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2363. *
  2364. * Copyright (c) 2012 Sergey Ilinsky
  2365. * Dual licensed under the MIT and GPL licenses.
  2366. *
  2367. *
  2368. */
  2369. function cVarRef(sPrefix, sLocalName, sNameSpaceURI) {
  2370. this.prefix = sPrefix;
  2371. this.localName = sLocalName;
  2372. this.namespaceURI = sNameSpaceURI;
  2373. };
  2374. cVarRef.prototype.prefix = null;
  2375. cVarRef.prototype.localName = null;
  2376. cVarRef.prototype.namespaceURI = null;
  2377. // Static members
  2378. function fVarRef_parse (oLexer, oStaticContext) {
  2379. if (oLexer.peek().substr(0, 1) == '$') {
  2380. var aMatch = oLexer.peek().substr(1).match(rNameTest);
  2381. if (aMatch) {
  2382. if (aMatch[1] == '*' || aMatch[2] == '*')
  2383. throw new cException("XPST0003"
  2384. );
  2385. var oVarRef = new cVarRef(aMatch[1] || null, aMatch[2], aMatch[1] ? oStaticContext.getURIForPrefix(aMatch[1]) : null);
  2386. oLexer.next();
  2387. return oVarRef;
  2388. }
  2389. }
  2390. };
  2391. // Public members
  2392. cVarRef.prototype.evaluate = function (oContext) {
  2393. var sUri = (this.namespaceURI ? '{' + this.namespaceURI + '}' : '') + this.localName;
  2394. if (oContext.scope.hasOwnProperty(sUri))
  2395. return [oContext.scope[sUri]];
  2396. //
  2397. throw new cException("XPST0008"
  2398. );
  2399. };
  2400. /*
  2401. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2402. *
  2403. * Copyright (c) 2012 Sergey Ilinsky
  2404. * Dual licensed under the MIT and GPL licenses.
  2405. *
  2406. *
  2407. */
  2408. function cFunctionCall(sPrefix, sLocalName, sNameSpaceURI) {
  2409. this.prefix = sPrefix;
  2410. this.localName = sLocalName;
  2411. this.namespaceURI = sNameSpaceURI;
  2412. this.args = [];
  2413. };
  2414. cFunctionCall.prototype.prefix = null;
  2415. cFunctionCall.prototype.localName = null;
  2416. cFunctionCall.prototype.namespaceURI = null;
  2417. cFunctionCall.prototype.args = null;
  2418. // Static members
  2419. function fFunctionCall_parse (oLexer, oStaticContext) {
  2420. var aMatch = oLexer.peek().match(rNameTest);
  2421. if (aMatch && oLexer.peek(1) == '(') {
  2422. // Reserved "functions"
  2423. if (!aMatch[1] && (aMatch[2] in hKindTest_names))
  2424. return fAxisStep_parse(oLexer, oStaticContext);
  2425. // Other functions
  2426. if (aMatch[1] == '*' || aMatch[2] == '*')
  2427. throw new cException("XPST0003"
  2428. );
  2429. var oFunctionCallExpr = new cFunctionCall(aMatch[1] || null, aMatch[2], aMatch[1] ? oStaticContext.getURIForPrefix(aMatch[1]) || null : oStaticContext.defaultFunctionNamespace),
  2430. oExpr;
  2431. oLexer.next(2);
  2432. //
  2433. if (oLexer.peek() != ')') {
  2434. do {
  2435. if (oLexer.eof() ||!(oExpr = fExprSingle_parse(oLexer, oStaticContext)))
  2436. throw new cException("XPST0003"
  2437. );
  2438. //
  2439. oFunctionCallExpr.args.push(oExpr);
  2440. }
  2441. while (oLexer.peek() == ',' && oLexer.next());
  2442. //
  2443. if (oLexer.peek() != ')')
  2444. throw new cException("XPST0003"
  2445. );
  2446. }
  2447. oLexer.next();
  2448. return oFunctionCallExpr;
  2449. }
  2450. };
  2451. // Public members
  2452. cFunctionCall.prototype.evaluate = function (oContext) {
  2453. var aArguments = [],
  2454. aParameters,
  2455. fFunction;
  2456. // Evaluate arguments
  2457. for (var nIndex = 0, nLength = this.args.length; nIndex < nLength; nIndex++)
  2458. aArguments.push(this.args[nIndex].evaluate(oContext));
  2459. var sUri = (this.namespaceURI ? '{' + this.namespaceURI + '}' : '') + this.localName;
  2460. // Call function
  2461. if (this.namespaceURI == sNS_XPF) {
  2462. if (fFunction = hStaticContext_functions[this.localName]) {
  2463. // Validate/Cast arguments
  2464. if (aParameters = hStaticContext_signatures[this.localName])
  2465. fFunctionCall_prepare(this.localName, aParameters, fFunction, aArguments, oContext);
  2466. //
  2467. var vResult = fFunction.apply(oContext, aArguments);
  2468. //
  2469. return vResult == null ? [] : vResult instanceof cArray ? vResult : [vResult];
  2470. }
  2471. throw new cException("XPST0017"
  2472. );
  2473. }
  2474. else
  2475. if (this.namespaceURI == sNS_XSD) {
  2476. if ((fFunction = hStaticContext_dataTypes[this.localName]) && this.localName != "NOTATION" && this.localName != "anyAtomicType") {
  2477. //
  2478. fFunctionCall_prepare(this.localName, [[cXSAnyAtomicType, '?']], fFunction, aArguments, oContext);
  2479. //
  2480. return aArguments[0] === null ? [] : [fFunction.cast(aArguments[0])];
  2481. }
  2482. throw new cException("XPST0017"
  2483. );
  2484. }
  2485. else
  2486. if (fFunction = oContext.staticContext.getFunction(sUri)) {
  2487. //
  2488. var vResult = fFunction.apply(oContext, aArguments);
  2489. //
  2490. return vResult == null ? [] : vResult instanceof cArray ? vResult : [vResult];
  2491. }
  2492. //
  2493. throw new cException("XPST0017"
  2494. );
  2495. };
  2496. var aFunctionCall_numbers = ["first", "second", "third", "fourth", "fifth"];
  2497. function fFunctionCall_prepare(sName, aParameters, fFunction, aArguments, oContext) {
  2498. var oArgument,
  2499. nArgumentsLength = aArguments.length,
  2500. oParameter,
  2501. nParametersLength = aParameters.length,
  2502. nParametersRequired = 0;
  2503. // Determine amount of parameters required
  2504. while ((nParametersRequired < aParameters.length) && !aParameters[nParametersRequired][2])
  2505. nParametersRequired++;
  2506. // Validate arguments length
  2507. if (nArgumentsLength > nParametersLength)
  2508. throw new cException("XPST0017"
  2509. );
  2510. else
  2511. if (nArgumentsLength < nParametersRequired)
  2512. throw new cException("XPST0017"
  2513. );
  2514. for (var nIndex = 0; nIndex < nArgumentsLength; nIndex++) {
  2515. oParameter = aParameters[nIndex];
  2516. oArgument = aArguments[nIndex];
  2517. // Check sequence cardinality
  2518. fFunctionCall_assertSequenceCardinality(oContext, oArgument, oParameter[1]
  2519. );
  2520. // Check sequence items data types consistency
  2521. fFunctionCall_assertSequenceItemType(oContext, oArgument, oParameter[0]
  2522. );
  2523. if (oParameter[1] != '+' && oParameter[1] != '*')
  2524. aArguments[nIndex] = oArgument.length ? oArgument[0] : null;
  2525. }
  2526. };
  2527. function fFunctionCall_assertSequenceItemType(oContext, oSequence, cItemType
  2528. ) {
  2529. //
  2530. for (var nIndex = 0, nLength = oSequence.length, nNodeType, vItem; nIndex < nLength; nIndex++) {
  2531. vItem = oSequence[nIndex];
  2532. // Node types
  2533. if (cItemType == cXTNode || cItemType.prototype instanceof cXTNode) {
  2534. // Check if is node
  2535. if (!oContext.DOMAdapter.isNode(vItem))
  2536. throw new cException("XPTY0004"
  2537. );
  2538. // Check node type
  2539. if (cItemType != cXTNode) {
  2540. nNodeType = oContext.DOMAdapter.getProperty(vItem, "nodeType");
  2541. if ([null, cXTElement, cXTAttribute, cXTText, cXTText, null, null, cXTProcessingInstruction, cXTComment, cXTDocument, null, null, null][nNodeType] != cItemType)
  2542. throw new cException("XPTY0004"
  2543. );
  2544. }
  2545. }
  2546. else
  2547. // Atomic types
  2548. if (cItemType == cXSAnyAtomicType || cItemType.prototype instanceof cXSAnyAtomicType) {
  2549. // Atomize item
  2550. vItem = fFunction_sequence_atomize([vItem], oContext)[0];
  2551. // Convert type if necessary
  2552. if (cItemType != cXSAnyAtomicType) {
  2553. // Cast item to expected type if it's type is xs:untypedAtomic
  2554. if (vItem instanceof cXSUntypedAtomic)
  2555. vItem = cItemType.cast(vItem);
  2556. // Cast item to xs:string if it's type is xs:anyURI
  2557. else
  2558. if (cItemType == cXSString/* || cItemType.prototype instanceof cXSString*/) {
  2559. if (vItem instanceof cXSAnyURI)
  2560. vItem = cXSString.cast(vItem);
  2561. }
  2562. else
  2563. if (cItemType == cXSDouble/* || cItemType.prototype instanceof cXSDouble*/) {
  2564. if (fXSAnyAtomicType_isNumeric(vItem))
  2565. vItem = cItemType.cast(vItem);
  2566. }
  2567. }
  2568. // Check type
  2569. if (!(vItem instanceof cItemType))
  2570. throw new cException("XPTY0004"
  2571. );
  2572. // Write value back to sequence
  2573. oSequence[nIndex] = vItem;
  2574. }
  2575. }
  2576. };
  2577. function fFunctionCall_assertSequenceCardinality(oContext, oSequence, sCardinality
  2578. ) {
  2579. var nLength = oSequence.length;
  2580. // Check cardinality
  2581. if (sCardinality == '?') { // =0 or 1
  2582. if (nLength > 1)
  2583. throw new cException("XPTY0004"
  2584. );
  2585. }
  2586. else
  2587. if (sCardinality == '+') { // =1+
  2588. if (nLength < 1)
  2589. throw new cException("XPTY0004"
  2590. );
  2591. }
  2592. else
  2593. if (sCardinality != '*') { // =1 ('*' =0+)
  2594. if (nLength != 1)
  2595. throw new cException("XPTY0004"
  2596. );
  2597. }
  2598. };
  2599. /*
  2600. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2601. *
  2602. * Copyright (c) 2012 Sergey Ilinsky
  2603. * Dual licensed under the MIT and GPL licenses.
  2604. *
  2605. *
  2606. */
  2607. function cIntersectExceptExpr(oExpr) {
  2608. this.left = oExpr;
  2609. this.items = [];
  2610. };
  2611. cIntersectExceptExpr.prototype.left = null;
  2612. cIntersectExceptExpr.prototype.items = null;
  2613. // Static members
  2614. function fIntersectExceptExpr_parse (oLexer, oStaticContext) {
  2615. var oExpr,
  2616. sOperator;
  2617. if (oLexer.eof() ||!(oExpr = fInstanceofExpr_parse(oLexer, oStaticContext)))
  2618. return;
  2619. if (!((sOperator = oLexer.peek()) == "intersect" || sOperator == "except"))
  2620. return oExpr;
  2621. // IntersectExcept expression
  2622. var oIntersectExceptExpr = new cIntersectExceptExpr(oExpr);
  2623. while ((sOperator = oLexer.peek()) == "intersect" || sOperator == "except") {
  2624. oLexer.next();
  2625. if (oLexer.eof() ||!(oExpr = fInstanceofExpr_parse(oLexer, oStaticContext)))
  2626. throw new cException("XPST0003"
  2627. );
  2628. oIntersectExceptExpr.items.push([sOperator, oExpr]);
  2629. }
  2630. return oIntersectExceptExpr;
  2631. };
  2632. // Public members
  2633. cIntersectExceptExpr.prototype.evaluate = function (oContext) {
  2634. var oSequence = this.left.evaluate(oContext);
  2635. for (var nIndex = 0, nLength = this.items.length, oItem; nIndex < nLength; nIndex++)
  2636. oSequence = hStaticContext_operators[(oItem = this.items[nIndex])[0]].call(oContext, oSequence, oItem[1].evaluate(oContext));
  2637. return oSequence;
  2638. };
  2639. /*
  2640. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2641. *
  2642. * Copyright (c) 2012 Sergey Ilinsky
  2643. * Dual licensed under the MIT and GPL licenses.
  2644. *
  2645. *
  2646. */
  2647. function cRangeExpr(oLeft, oRight) {
  2648. this.left = oLeft;
  2649. this.right = oRight;
  2650. };
  2651. cRangeExpr.prototype.left = null;
  2652. cRangeExpr.prototype.right = null;
  2653. // Static members
  2654. function fRangeExpr_parse (oLexer, oStaticContext) {
  2655. var oExpr,
  2656. oRight;
  2657. if (oLexer.eof() ||!(oExpr = fAdditiveExpr_parse(oLexer, oStaticContext)))
  2658. return;
  2659. if (oLexer.peek() != "to")
  2660. return oExpr;
  2661. // Range expression
  2662. oLexer.next();
  2663. if (oLexer.eof() ||!(oRight = fAdditiveExpr_parse(oLexer, oStaticContext)))
  2664. throw new cException("XPST0003"
  2665. );
  2666. return new cRangeExpr(oExpr, oRight);
  2667. };
  2668. // Public members
  2669. cRangeExpr.prototype.evaluate = function (oContext) {
  2670. //
  2671. var oLeft = this.left.evaluate(oContext);
  2672. if (!oLeft.length)
  2673. return [];
  2674. //
  2675. fFunctionCall_assertSequenceCardinality(oContext, oLeft, '?'
  2676. );
  2677. fFunctionCall_assertSequenceItemType(oContext, oLeft, cXSInteger
  2678. );
  2679. var oRight = this.right.evaluate(oContext);
  2680. if (!oRight.length)
  2681. return [];
  2682. fFunctionCall_assertSequenceCardinality(oContext, oRight, '?'
  2683. );
  2684. fFunctionCall_assertSequenceItemType(oContext, oRight, cXSInteger
  2685. );
  2686. return hStaticContext_operators["to"].call(oContext, oLeft[0], oRight[0]);
  2687. };
  2688. /*
  2689. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2690. *
  2691. * Copyright (c) 2012 Sergey Ilinsky
  2692. * Dual licensed under the MIT and GPL licenses.
  2693. *
  2694. *
  2695. */
  2696. function cUnionExpr(oExpr) {
  2697. this.left = oExpr;
  2698. this.items = [];
  2699. };
  2700. cUnionExpr.prototype.left = null;
  2701. cUnionExpr.prototype.items = null;
  2702. // Static members
  2703. function fUnionExpr_parse (oLexer, oStaticContext) {
  2704. var oExpr,
  2705. sOperator;
  2706. if (oLexer.eof() ||!(oExpr = fIntersectExceptExpr_parse(oLexer, oStaticContext)))
  2707. return;
  2708. if (!((sOperator = oLexer.peek()) == '|' || sOperator == "union"))
  2709. return oExpr;
  2710. // Union expression
  2711. var oUnionExpr = new cUnionExpr(oExpr);
  2712. while ((sOperator = oLexer.peek()) == '|' || sOperator == "union") {
  2713. oLexer.next();
  2714. if (oLexer.eof() ||!(oExpr = fIntersectExceptExpr_parse(oLexer, oStaticContext)))
  2715. throw new cException("XPST0003"
  2716. );
  2717. oUnionExpr.items.push(oExpr);
  2718. }
  2719. return oUnionExpr;
  2720. };
  2721. // Public members
  2722. cUnionExpr.prototype.evaluate = function (oContext) {
  2723. var oSequence = this.left.evaluate(oContext);
  2724. for (var nIndex = 0, nLength = this.items.length; nIndex < nLength; nIndex++)
  2725. oSequence = hStaticContext_operators["union"].call(oContext, oSequence, this.items[nIndex].evaluate(oContext));
  2726. return oSequence;
  2727. };
  2728. /*
  2729. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2730. *
  2731. * Copyright (c) 2012 Sergey Ilinsky
  2732. * Dual licensed under the MIT and GPL licenses.
  2733. *
  2734. *
  2735. */
  2736. function cInstanceofExpr(oExpr, oType) {
  2737. this.expression = oExpr;
  2738. this.type = oType;
  2739. };
  2740. cInstanceofExpr.prototype.expression = null;
  2741. cInstanceofExpr.prototype.type = null;
  2742. function fInstanceofExpr_parse (oLexer, oStaticContext) {
  2743. var oExpr,
  2744. oType;
  2745. if (oLexer.eof() ||!(oExpr = fTreatExpr_parse(oLexer, oStaticContext)))
  2746. return;
  2747. if (!(oLexer.peek() == "instance" && oLexer.peek(1) == "of"))
  2748. return oExpr;
  2749. oLexer.next(2);
  2750. if (oLexer.eof() ||!(oType = fSequenceType_parse(oLexer, oStaticContext)))
  2751. throw new cException("XPST0003"
  2752. );
  2753. return new cInstanceofExpr(oExpr, oType);
  2754. };
  2755. cInstanceofExpr.prototype.evaluate = function(oContext) {
  2756. var oSequence1 = this.expression.evaluate(oContext),
  2757. oItemType = this.type.itemType,
  2758. sOccurence = this.type.occurence;
  2759. // Validate empty-sequence()
  2760. if (!oItemType)
  2761. return [new cXSBoolean(!oSequence1.length)];
  2762. // Validate cardinality
  2763. if (!oSequence1.length)
  2764. return [new cXSBoolean(sOccurence == '?' || sOccurence == '*')];
  2765. if (oSequence1.length != 1)
  2766. if (!(sOccurence == '+' || sOccurence == '*'))
  2767. return [new cXSBoolean(false)];
  2768. // Validate type
  2769. if (!oItemType.test) // item()
  2770. return [new cXSBoolean(true)];
  2771. var bValue = true;
  2772. for (var nIndex = 0, nLength = oSequence1.length; (nIndex < nLength) && bValue; nIndex++)
  2773. bValue = oItemType.test.test(oSequence1[nIndex], oContext);
  2774. //
  2775. return [new cXSBoolean(bValue)];
  2776. };
  2777. /*
  2778. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2779. *
  2780. * Copyright (c) 2012 Sergey Ilinsky
  2781. * Dual licensed under the MIT and GPL licenses.
  2782. *
  2783. *
  2784. */
  2785. function cTreatExpr(oExpr, oType) {
  2786. this.expression = oExpr;
  2787. this.type = oType;
  2788. };
  2789. cTreatExpr.prototype.expression = null;
  2790. cTreatExpr.prototype.type = null;
  2791. function fTreatExpr_parse (oLexer, oStaticContext) {
  2792. var oExpr,
  2793. oType;
  2794. if (oLexer.eof() ||!(oExpr = fCastableExpr_parse(oLexer, oStaticContext)))
  2795. return;
  2796. if (!(oLexer.peek() == "treat" && oLexer.peek(1) == "as"))
  2797. return oExpr;
  2798. oLexer.next(2);
  2799. if (oLexer.eof() ||!(oType = fSequenceType_parse(oLexer, oStaticContext)))
  2800. throw new cException("XPST0003"
  2801. );
  2802. return new cTreatExpr(oExpr, oType);
  2803. };
  2804. cTreatExpr.prototype.evaluate = function(oContext) {
  2805. var oSequence1 = this.expression.evaluate(oContext),
  2806. oItemType = this.type.itemType,
  2807. sOccurence = this.type.occurence;
  2808. // Validate empty-sequence()
  2809. if (!oItemType) {
  2810. if (oSequence1.length)
  2811. throw new cException("XPDY0050"
  2812. );
  2813. return oSequence1;
  2814. }
  2815. // Validate cardinality
  2816. if (!(sOccurence == '?' || sOccurence == '*'))
  2817. if (!oSequence1.length)
  2818. throw new cException("XPDY0050"
  2819. );
  2820. if (!(sOccurence == '+' || sOccurence == '*'))
  2821. if (oSequence1.length != 1)
  2822. throw new cException("XPDY0050"
  2823. );
  2824. // Validate type
  2825. if (!oItemType.test) // item()
  2826. return oSequence1;
  2827. for (var nIndex = 0, nLength = oSequence1.length; nIndex < nLength; nIndex++)
  2828. if (!oItemType.test.test(oSequence1[nIndex], oContext))
  2829. throw new cException("XPDY0050"
  2830. );
  2831. //
  2832. return oSequence1;
  2833. };
  2834. /*
  2835. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2836. *
  2837. * Copyright (c) 2012 Sergey Ilinsky
  2838. * Dual licensed under the MIT and GPL licenses.
  2839. *
  2840. *
  2841. */
  2842. function cCastableExpr(oExpr, oType) {
  2843. this.expression = oExpr;
  2844. this.type = oType;
  2845. };
  2846. cCastableExpr.prototype.expression = null;
  2847. cCastableExpr.prototype.type = null;
  2848. function fCastableExpr_parse (oLexer, oStaticContext) {
  2849. var oExpr,
  2850. oType;
  2851. if (oLexer.eof() ||!(oExpr = fCastExpr_parse(oLexer, oStaticContext)))
  2852. return;
  2853. if (!(oLexer.peek() == "castable" && oLexer.peek(1) == "as"))
  2854. return oExpr;
  2855. oLexer.next(2);
  2856. if (oLexer.eof() ||!(oType = fSingleType_parse(oLexer, oStaticContext)))
  2857. throw new cException("XPST0003"
  2858. );
  2859. return new cCastableExpr(oExpr, oType);
  2860. };
  2861. cCastableExpr.prototype.evaluate = function(oContext) {
  2862. var oSequence1 = this.expression.evaluate(oContext),
  2863. oItemType = this.type.itemType,
  2864. sOccurence = this.type.occurence;
  2865. if (oSequence1.length > 1)
  2866. return [new cXSBoolean(false)];
  2867. else
  2868. if (!oSequence1.length)
  2869. return [new cXSBoolean(sOccurence == '?')];
  2870. // Try casting
  2871. try {
  2872. oItemType.cast(fFunction_sequence_atomize(oSequence1, oContext)[0]);
  2873. }
  2874. catch (e) {
  2875. if (e.code == "XPST0051")
  2876. throw e;
  2877. if (e.code == "XPST0017")
  2878. throw new cException("XPST0080"
  2879. );
  2880. //
  2881. return [new cXSBoolean(false)];
  2882. }
  2883. return [new cXSBoolean(true)];
  2884. };
  2885. /*
  2886. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2887. *
  2888. * Copyright (c) 2012 Sergey Ilinsky
  2889. * Dual licensed under the MIT and GPL licenses.
  2890. *
  2891. *
  2892. */
  2893. function cCastExpr(oExpr, oType) {
  2894. this.expression = oExpr;
  2895. this.type = oType;
  2896. };
  2897. cCastExpr.prototype.expression = null;
  2898. cCastExpr.prototype.type = null;
  2899. function fCastExpr_parse (oLexer, oStaticContext) {
  2900. var oExpr,
  2901. oType;
  2902. if (oLexer.eof() ||!(oExpr = fUnaryExpr_parse(oLexer, oStaticContext)))
  2903. return;
  2904. if (!(oLexer.peek() == "cast" && oLexer.peek(1) == "as"))
  2905. return oExpr;
  2906. oLexer.next(2);
  2907. if (oLexer.eof() ||!(oType = fSingleType_parse(oLexer, oStaticContext)))
  2908. throw new cException("XPST0003"
  2909. );
  2910. return new cCastExpr(oExpr, oType);
  2911. };
  2912. cCastExpr.prototype.evaluate = function(oContext) {
  2913. var oSequence1 = this.expression.evaluate(oContext);
  2914. // Validate cardinality
  2915. fFunctionCall_assertSequenceCardinality(oContext, oSequence1, this.type.occurence
  2916. );
  2917. //
  2918. if (!oSequence1.length)
  2919. return [];
  2920. //
  2921. return [this.type.itemType.cast(fFunction_sequence_atomize(oSequence1, oContext)[0], oContext)];
  2922. };
  2923. /*
  2924. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2925. *
  2926. * Copyright (c) 2012 Sergey Ilinsky
  2927. * Dual licensed under the MIT and GPL licenses.
  2928. *
  2929. *
  2930. */
  2931. function cAtomicType(sPrefix, sLocalName, sNameSpaceURI) {
  2932. this.prefix = sPrefix;
  2933. this.localName = sLocalName;
  2934. this.namespaceURI = sNameSpaceURI;
  2935. };
  2936. cAtomicType.prototype.prefix = null;
  2937. cAtomicType.prototype.localName = null;
  2938. cAtomicType.prototype.namespaceURI = null;
  2939. function fAtomicType_parse (oLexer, oStaticContext) {
  2940. var aMatch = oLexer.peek().match(rNameTest);
  2941. if (aMatch) {
  2942. if (aMatch[1] == '*' || aMatch[2] == '*')
  2943. throw new cException("XPST0003"
  2944. );
  2945. oLexer.next();
  2946. return new cAtomicType(aMatch[1] || null, aMatch[2], aMatch[1] ? oStaticContext.getURIForPrefix(aMatch[1]) : null);
  2947. }
  2948. };
  2949. cAtomicType.prototype.test = function(vItem, oContext) {
  2950. // Test
  2951. var sUri = (this.namespaceURI ? '{' + this.namespaceURI + '}' : '') + this.localName,
  2952. cType = this.namespaceURI == sNS_XSD ? hStaticContext_dataTypes[this.localName] : oContext.staticContext.getDataType(sUri);
  2953. if (cType)
  2954. return vItem instanceof cType;
  2955. //
  2956. throw new cException("XPST0051"
  2957. );
  2958. };
  2959. cAtomicType.prototype.cast = function(vItem, oContext) {
  2960. // Cast
  2961. var sUri = (this.namespaceURI ? '{' + this.namespaceURI + '}' : '') + this.localName,
  2962. cType = this.namespaceURI == sNS_XSD ? hStaticContext_dataTypes[this.localName] : oContext.staticContext.getDataType(sUri);
  2963. if (cType)
  2964. return cType.cast(vItem);
  2965. //
  2966. throw new cException("XPST0051"
  2967. );
  2968. };
  2969. /*
  2970. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  2971. *
  2972. * Copyright (c) 2012 Sergey Ilinsky
  2973. * Dual licensed under the MIT and GPL licenses.
  2974. *
  2975. *
  2976. */
  2977. function cItemType(oTest) {
  2978. this.test = oTest;
  2979. };
  2980. cItemType.prototype.test = null;
  2981. function fItemType_parse (oLexer, oStaticContext) {
  2982. if (oLexer.eof())
  2983. return;
  2984. var oExpr;
  2985. if (oLexer.peek() == "item" && oLexer.peek(1) == '(') {
  2986. oLexer.next(2);
  2987. if (oLexer.peek() != ')')
  2988. throw new cException("XPST0003"
  2989. );
  2990. oLexer.next();
  2991. return new cItemType;
  2992. }
  2993. // Note! Following step should have been before previous as per spec
  2994. if (oExpr = fKindTest_parse(oLexer, oStaticContext))
  2995. return new cItemType(oExpr);
  2996. if (oExpr = fAtomicType_parse(oLexer, oStaticContext))
  2997. return new cItemType(oExpr);
  2998. };
  2999. /*
  3000. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3001. *
  3002. * Copyright (c) 2012 Sergey Ilinsky
  3003. * Dual licensed under the MIT and GPL licenses.
  3004. *
  3005. *
  3006. */
  3007. function cSequenceType(oItemType, sOccurence) {
  3008. this.itemType = oItemType || null;
  3009. this.occurence = sOccurence|| null;
  3010. };
  3011. cSequenceType.prototype.itemType = null;
  3012. cSequenceType.prototype.occurence = null;
  3013. function fSequenceType_parse (oLexer, oStaticContext) {
  3014. if (oLexer.eof())
  3015. return;
  3016. if (oLexer.peek() == "empty-sequence" && oLexer.peek(1) == '(') {
  3017. oLexer.next(2);
  3018. if (oLexer.peek() != ')')
  3019. throw new cException("XPST0003"
  3020. );
  3021. oLexer.next();
  3022. return new cSequenceType; // empty sequence
  3023. }
  3024. var oExpr,
  3025. sOccurence;
  3026. if (!oLexer.eof() && (oExpr = fItemType_parse(oLexer, oStaticContext))) {
  3027. sOccurence = oLexer.peek();
  3028. if (sOccurence == '?' || sOccurence == '*' || sOccurence == '+')
  3029. oLexer.next();
  3030. else
  3031. sOccurence = null;
  3032. return new cSequenceType(oExpr, sOccurence);
  3033. }
  3034. };
  3035. /*
  3036. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3037. *
  3038. * Copyright (c) 2012 Sergey Ilinsky
  3039. * Dual licensed under the MIT and GPL licenses.
  3040. *
  3041. *
  3042. */
  3043. function cSingleType(oItemType, sOccurence) {
  3044. this.itemType = oItemType || null;
  3045. this.occurence = sOccurence|| null;
  3046. };
  3047. cSingleType.prototype.itemType = null;
  3048. cSingleType.prototype.occurence = null;
  3049. function fSingleType_parse (oLexer, oStaticContext) {
  3050. var oExpr,
  3051. sOccurence;
  3052. if (!oLexer.eof() && (oExpr = fAtomicType_parse(oLexer, oStaticContext))) {
  3053. sOccurence = oLexer.peek();
  3054. if (sOccurence == '?')
  3055. oLexer.next();
  3056. else
  3057. sOccurence = null;
  3058. return new cSingleType(oExpr, sOccurence);
  3059. }
  3060. };
  3061. /*
  3062. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3063. *
  3064. * Copyright (c) 2012 Sergey Ilinsky
  3065. * Dual licensed under the MIT and GPL licenses.
  3066. *
  3067. *
  3068. */
  3069. function cXSAnyType() {
  3070. };
  3071. cXSAnyType.prototype.builtInKind = cXSConstants.ANYTYPE_DT;
  3072. /*
  3073. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3074. *
  3075. * Copyright (c) 2012 Sergey Ilinsky
  3076. * Dual licensed under the MIT and GPL licenses.
  3077. *
  3078. *
  3079. */
  3080. function cXSAnySimpleType() {
  3081. };
  3082. cXSAnySimpleType.prototype = new cXSAnyType;
  3083. cXSAnySimpleType.prototype.builtInKind = cXSConstants.ANYSIMPLETYPE_DT;
  3084. cXSAnySimpleType.prototype.primitiveKind= null;
  3085. cXSAnySimpleType.PRIMITIVE_ANYURI = "anyURI"; //18;
  3086. cXSAnySimpleType.PRIMITIVE_BASE64BINARY = "base64Binary"; // 17;
  3087. cXSAnySimpleType.PRIMITIVE_BOOLEAN = "boolean"; // 3;
  3088. cXSAnySimpleType.PRIMITIVE_DATE = "date"; // 10;
  3089. cXSAnySimpleType.PRIMITIVE_DATETIME = "dateTime"; // 8;
  3090. cXSAnySimpleType.PRIMITIVE_DECIMAL = "decimal"; // 4;
  3091. cXSAnySimpleType.PRIMITIVE_DOUBLE = "double"; // 6;
  3092. cXSAnySimpleType.PRIMITIVE_DURATION = "duration"; // 7;
  3093. cXSAnySimpleType.PRIMITIVE_FLOAT = "float"; // 5;
  3094. cXSAnySimpleType.PRIMITIVE_GDAY = "gDay"; // 14;
  3095. cXSAnySimpleType.PRIMITIVE_GMONTH = "gMonth"; // 15;
  3096. cXSAnySimpleType.PRIMITIVE_GMONTHDAY = "gMonthDay"; // 13;
  3097. cXSAnySimpleType.PRIMITIVE_GYEAR = "gYear"; // 12;
  3098. cXSAnySimpleType.PRIMITIVE_GYEARMONTH = "gYearMonth"; // 11;
  3099. cXSAnySimpleType.PRIMITIVE_HEXBINARY = "hexBinary"; // 16;
  3100. cXSAnySimpleType.PRIMITIVE_NOTATION = "NOTATION"; // 20;
  3101. cXSAnySimpleType.PRIMITIVE_QNAME = "QName"; // 19;
  3102. cXSAnySimpleType.PRIMITIVE_STRING = "string"; // 2;
  3103. cXSAnySimpleType.PRIMITIVE_TIME = "time"; // 9;
  3104. /*
  3105. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3106. *
  3107. * Copyright (c) 2012 Sergey Ilinsky
  3108. * Dual licensed under the MIT and GPL licenses.
  3109. *
  3110. *
  3111. */
  3112. function cXSAnyAtomicType() {
  3113. };
  3114. cXSAnyAtomicType.prototype = new cXSAnySimpleType;
  3115. cXSAnyAtomicType.prototype.builtInKind = cXSConstants.ANYATOMICTYPE_DT;
  3116. cXSAnyAtomicType.cast = function(vValue) {
  3117. throw new cException("XPST0017"
  3118. ); // {http://www.w3.org/2001/XMLSchema}anyAtomicType
  3119. };
  3120. function fXSAnyAtomicType_isNumeric(vItem) {
  3121. return vItem instanceof cXSFloat || vItem instanceof cXSDouble || vItem instanceof cXSDecimal;
  3122. };
  3123. //
  3124. fStaticContext_defineSystemDataType("anyAtomicType", cXSAnyAtomicType);
  3125. /*
  3126. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3127. *
  3128. * Copyright (c) 2012 Sergey Ilinsky
  3129. * Dual licensed under the MIT and GPL licenses.
  3130. *
  3131. *
  3132. */
  3133. function cXSAnyURI(sScheme, sAuthority, sPath, sQuery, sFragment) {
  3134. this.scheme = sScheme;
  3135. this.authority = sAuthority;
  3136. this.path = sPath;
  3137. this.query = sQuery;
  3138. this.fragment = sFragment;
  3139. };
  3140. cXSAnyURI.prototype = new cXSAnyAtomicType;
  3141. cXSAnyURI.prototype.builtInKind = cXSConstants.ANYURI_DT;
  3142. cXSAnyURI.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_ANYURI;
  3143. cXSAnyURI.prototype.scheme = null;
  3144. cXSAnyURI.prototype.authority = null;
  3145. cXSAnyURI.prototype.path = null;
  3146. cXSAnyURI.prototype.query = null;
  3147. cXSAnyURI.prototype.fragment = null;
  3148. cXSAnyURI.prototype.toString = function() {
  3149. return (this.scheme ? this.scheme + ':' : '')
  3150. + (this.authority ? '/' + '/' + this.authority : '')
  3151. + (this.path ? this.path : '')
  3152. + (this.query ? '?' + this.query : '')
  3153. + (this.fragment ? '#' + this.fragment : '');
  3154. };
  3155. var rXSAnyURI = /^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/; // http://tools.ietf.org/html/rfc3986
  3156. cXSAnyURI.cast = function(vValue) {
  3157. if (vValue instanceof cXSAnyURI)
  3158. return vValue;
  3159. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  3160. var aMatch;
  3161. if (aMatch = fString_trim(vValue).match(rXSAnyURI))
  3162. return new cXSAnyURI(aMatch[2], aMatch[4], aMatch[5], aMatch[7], aMatch[9]);
  3163. throw new cException("FORG0001");
  3164. }
  3165. //
  3166. throw new cException("XPTY0004"
  3167. );
  3168. };
  3169. //
  3170. fStaticContext_defineSystemDataType("anyURI", cXSAnyURI);
  3171. /*
  3172. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3173. *
  3174. * Copyright (c) 2012 Sergey Ilinsky
  3175. * Dual licensed under the MIT and GPL licenses.
  3176. *
  3177. *
  3178. */
  3179. function cXSBase64Binary(sValue) {
  3180. this.value = sValue;
  3181. };
  3182. cXSBase64Binary.prototype = new cXSAnyAtomicType;
  3183. cXSBase64Binary.prototype.builtInKind = cXSConstants.BASE64BINARY_DT;
  3184. cXSBase64Binary.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_BASE64BINARY;
  3185. cXSBase64Binary.prototype.value = null;
  3186. cXSBase64Binary.prototype.valueOf = function() {
  3187. return this.value;
  3188. };
  3189. cXSBase64Binary.prototype.toString = function() {
  3190. return this.value;
  3191. };
  3192. var rXSBase64Binary = /^((([A-Za-z0-9+\/]\s*){4})*(([A-Za-z0-9+\/]\s*){3}[A-Za-z0-9+\/]|([A-Za-z0-9+\/]\s*){2}[AEIMQUYcgkosw048]\s*=|[A-Za-z0-9+\/]\s*[AQgw]\s*=\s*=))?$/;
  3193. cXSBase64Binary.cast = function(vValue) {
  3194. if (vValue instanceof cXSBase64Binary)
  3195. return vValue;
  3196. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  3197. var aMatch = fString_trim(vValue).match(rXSBase64Binary);
  3198. if (aMatch)
  3199. return new cXSBase64Binary(aMatch[0]);
  3200. throw new cException("FORG0001");
  3201. }
  3202. if (vValue instanceof cXSHexBinary) {
  3203. var aMatch = vValue.valueOf().match(/.{2}/g),
  3204. aValue = [];
  3205. for (var nIndex = 0, nLength = aMatch.length; nIndex < nLength; nIndex++)
  3206. aValue.push(cString.fromCharCode(fWindow_parseInt(aMatch[nIndex], 16)));
  3207. return new cXSBase64Binary(fWindow_btoa(aValue.join('')));
  3208. }
  3209. //
  3210. throw new cException("XPTY0004"
  3211. );
  3212. };
  3213. //
  3214. fStaticContext_defineSystemDataType("base64Binary", cXSBase64Binary);
  3215. /*
  3216. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3217. *
  3218. * Copyright (c) 2012 Sergey Ilinsky
  3219. * Dual licensed under the MIT and GPL licenses.
  3220. *
  3221. *
  3222. */
  3223. function cXSBoolean(bValue) {
  3224. this.value = bValue;
  3225. };
  3226. cXSBoolean.prototype = new cXSAnyAtomicType;
  3227. cXSBoolean.prototype.builtInKind = cXSConstants.BOOLEAN_DT;
  3228. cXSBoolean.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_BOOLEAN;
  3229. cXSBoolean.prototype.value = null;
  3230. cXSBoolean.prototype.valueOf = function() {
  3231. return this.value;
  3232. };
  3233. cXSBoolean.prototype.toString = function() {
  3234. return cString(this.value);
  3235. };
  3236. var rXSBoolean = /^(0|1|true|false)$/;
  3237. cXSBoolean.cast = function(vValue) {
  3238. if (vValue instanceof cXSBoolean)
  3239. return vValue;
  3240. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  3241. var aMatch;
  3242. if (aMatch = fString_trim(vValue).match(rXSBoolean))
  3243. return new cXSBoolean(aMatch[1] == '1' || aMatch[1] == "true");
  3244. throw new cException("FORG0001");
  3245. }
  3246. if (fXSAnyAtomicType_isNumeric(vValue))
  3247. return new cXSBoolean(vValue != 0);
  3248. //
  3249. throw new cException("XPTY0004"
  3250. );
  3251. };
  3252. //
  3253. fStaticContext_defineSystemDataType("boolean", cXSBoolean);
  3254. /*
  3255. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3256. *
  3257. * Copyright (c) 2012 Sergey Ilinsky
  3258. * Dual licensed under the MIT and GPL licenses.
  3259. *
  3260. *
  3261. */
  3262. function cXSDate(nYear, nMonth, nDay, nTimezone, bNegative) {
  3263. this.year = nYear;
  3264. this.month = nMonth;
  3265. this.day = nDay;
  3266. this.timezone = nTimezone;
  3267. this.negative = bNegative;
  3268. };
  3269. cXSDate.prototype = new cXSAnyAtomicType;
  3270. cXSDate.prototype.builtInKind = cXSConstants.DATE_DT;
  3271. cXSDate.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_DATE;
  3272. cXSDate.prototype.year = null;
  3273. cXSDate.prototype.month = null;
  3274. cXSDate.prototype.day = null;
  3275. cXSDate.prototype.timezone = null;
  3276. cXSDate.prototype.negative = null;
  3277. cXSDate.prototype.toString = function() {
  3278. return fXSDateTime_getDateComponent(this)
  3279. + fXSDateTime_getTZComponent(this);
  3280. };
  3281. var rXSDate = /^(-?)([1-9]\d\d\d+|0\d\d\d)-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])(Z|([+\-])(0\d|1[0-4]):([0-5]\d))?$/;
  3282. cXSDate.cast = function(vValue) {
  3283. if (vValue instanceof cXSDate)
  3284. return vValue;
  3285. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  3286. var aMatch = fString_trim(vValue).match(rXSDate);
  3287. if (aMatch) {
  3288. var nYear = +aMatch[2],
  3289. nMonth = +aMatch[3],
  3290. nDay = +aMatch[4];
  3291. if (nDay - 1 < fXSDate_getDaysForYearMonth(nYear, nMonth))
  3292. return new cXSDate( nYear,
  3293. nMonth,
  3294. nDay,
  3295. aMatch[5] ? aMatch[5] == 'Z' ? 0 : (aMatch[6] == '-' ? -1 : 1) * (aMatch[7] * 60 + aMatch[8] * 1) : null,
  3296. aMatch[1] == '-'
  3297. );
  3298. //
  3299. throw new cException("FORG0001"
  3300. );
  3301. }
  3302. throw new cException("FORG0001");
  3303. }
  3304. if (vValue instanceof cXSDateTime)
  3305. return new cXSDate(vValue.year, vValue.month, vValue.day, vValue.timezone, vValue.negative);
  3306. //
  3307. throw new cException("XPTY0004"
  3308. );
  3309. };
  3310. // Utilities
  3311. var aXSDate_days = [31,28,31,30,31,30,31,31,30,31,30,31];
  3312. function fXSDate_getDaysForYearMonth(nYear, nMonth) {
  3313. return nMonth == 2 && (nYear % 400 == 0 || nYear % 100 != 0 && nYear % 4 == 0) ? 29 : aXSDate_days[nMonth - 1];
  3314. };
  3315. function fXSDate_normalize(oValue, bDay) {
  3316. // Adjust day for month/year
  3317. if (!bDay) {
  3318. var nDay = fXSDate_getDaysForYearMonth(oValue.year, oValue.month);
  3319. if (oValue.day > nDay) {
  3320. while (oValue.day > nDay) {
  3321. oValue.month += 1;
  3322. if (oValue.month > 12) {
  3323. oValue.year += 1;
  3324. if (oValue.year == 0)
  3325. oValue.year = 1;
  3326. oValue.month = 1;
  3327. }
  3328. oValue.day -= nDay;
  3329. nDay = fXSDate_getDaysForYearMonth(oValue.year, oValue.month);
  3330. }
  3331. }
  3332. else
  3333. if (oValue.day < 1) {
  3334. while (oValue.day < 1) {
  3335. oValue.month -= 1;
  3336. if (oValue.month < 1) {
  3337. oValue.year -= 1;
  3338. if (oValue.year == 0)
  3339. oValue.year =-1;
  3340. oValue.month = 12;
  3341. }
  3342. nDay = fXSDate_getDaysForYearMonth(oValue.year, oValue.month);
  3343. oValue.day += nDay;
  3344. }
  3345. }
  3346. }
  3347. //? else
  3348. // Adjust month
  3349. if (oValue.month > 12) {
  3350. oValue.year += ~~(oValue.month / 12);
  3351. if (oValue.year == 0)
  3352. oValue.year = 1;
  3353. oValue.month = oValue.month % 12;
  3354. }
  3355. else
  3356. if (oValue.month < 1) {
  3357. oValue.year += ~~(oValue.month / 12) - 1;
  3358. if (oValue.year == 0)
  3359. oValue.year =-1;
  3360. oValue.month = oValue.month % 12 + 12;
  3361. }
  3362. return oValue;
  3363. };
  3364. //
  3365. fStaticContext_defineSystemDataType("date", cXSDate);
  3366. /*
  3367. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3368. *
  3369. * Copyright (c) 2012 Sergey Ilinsky
  3370. * Dual licensed under the MIT and GPL licenses.
  3371. *
  3372. *
  3373. */
  3374. function cXSDateTime(nYear, nMonth, nDay, nHours, nMinutes, nSeconds, nTimezone, bNegative) {
  3375. this.year = nYear;
  3376. this.month = nMonth;
  3377. this.day = nDay;
  3378. this.hours = nHours;
  3379. this.minutes = nMinutes;
  3380. this.seconds = nSeconds;
  3381. this.timezone = nTimezone;
  3382. this.negative = bNegative;
  3383. };
  3384. cXSDateTime.prototype = new cXSAnyAtomicType;
  3385. cXSDateTime.prototype.builtInKind = cXSConstants.DATETIME_DT;
  3386. cXSDateTime.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_DATETIME;
  3387. cXSDateTime.prototype.year = null;
  3388. cXSDateTime.prototype.month = null;
  3389. cXSDateTime.prototype.day = null;
  3390. cXSDateTime.prototype.hours = null;
  3391. cXSDateTime.prototype.minutes = null;
  3392. cXSDateTime.prototype.seconds = null;
  3393. cXSDateTime.prototype.timezone = null;
  3394. cXSDateTime.prototype.negative = null;
  3395. cXSDateTime.prototype.toString = function() {
  3396. return fXSDateTime_getDateComponent(this)
  3397. + 'T'
  3398. + fXSDateTime_getTimeComponent(this)
  3399. + fXSDateTime_getTZComponent(this);
  3400. };
  3401. var rXSDateTime = /^(-?)([1-9]\d\d\d+|0\d\d\d)-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])T(([01]\d|2[0-3]):([0-5]\d):([0-5]\d)(?:\.(\d+))?|(24:00:00)(?:\.(0+))?)(Z|([+\-])(0\d|1[0-4]):([0-5]\d))?$/;
  3402. cXSDateTime.cast = function(vValue) {
  3403. if (vValue instanceof cXSDateTime)
  3404. return vValue;
  3405. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  3406. var aMatch = fString_trim(vValue).match(rXSDateTime);
  3407. if (aMatch) {
  3408. var nYear = +aMatch[2],
  3409. nMonth = +aMatch[3],
  3410. nDay = +aMatch[4],
  3411. bValue = !!aMatch[10];
  3412. if (nDay - 1 < fXSDate_getDaysForYearMonth(nYear, nMonth))
  3413. return fXSDateTime_normalize(new cXSDateTime( nYear,
  3414. nMonth,
  3415. nDay,
  3416. bValue ? 24 : +aMatch[6],
  3417. bValue ? 0 : +aMatch[7],
  3418. cNumber((bValue ? 0 : aMatch[8]) + '.' + (bValue ? 0 : aMatch[9] || 0)),
  3419. aMatch[12] ? aMatch[12] == 'Z' ? 0 : (aMatch[13] == '-' ? -1 : 1) * (aMatch[14] * 60 + aMatch[15] * 1) : null,
  3420. aMatch[1] == '-'
  3421. ));
  3422. //
  3423. throw new cException("FORG0001"
  3424. );
  3425. }
  3426. throw new cException("FORG0001");
  3427. }
  3428. if (vValue instanceof cXSDate)
  3429. return new cXSDateTime(vValue.year, vValue.month, vValue.day, 0, 0, 0, vValue.timezone, vValue.negative);
  3430. //
  3431. throw new cException("XPTY0004"
  3432. );
  3433. };
  3434. // Utilities
  3435. function fXSDateTime_pad(vValue, nLength) {
  3436. var sValue = cString(vValue);
  3437. if (arguments.length < 2)
  3438. nLength = 2;
  3439. return (sValue.length < nLength + 1 ? new cArray(nLength + 1 - sValue.length).join('0') : '') + sValue;
  3440. };
  3441. function fXSDateTime_getTZComponent(oDateTime) {
  3442. var nTimezone = oDateTime.timezone;
  3443. return nTimezone == null
  3444. ? ''
  3445. : nTimezone
  3446. ? (nTimezone > 0 ? '+' : '-')
  3447. + fXSDateTime_pad(cMath.abs(~~(nTimezone / 60)))
  3448. + ':'
  3449. + fXSDateTime_pad(cMath.abs(nTimezone % 60))
  3450. : 'Z';
  3451. };
  3452. function fXSDateTime_getDateComponent(oDateTime) {
  3453. return (oDateTime.negative ? '-' : '')
  3454. + fXSDateTime_pad(oDateTime.year, 4)
  3455. + '-' + fXSDateTime_pad(oDateTime.month)
  3456. + '-' + fXSDateTime_pad(oDateTime.day);
  3457. };
  3458. function fXSDateTime_getTimeComponent(oDateTime) {
  3459. var aValue = cString(oDateTime.seconds).split('.');
  3460. return fXSDateTime_pad(oDateTime.hours)
  3461. + ':' + fXSDateTime_pad(oDateTime.minutes)
  3462. + ':' + fXSDateTime_pad(aValue[0])
  3463. + (aValue.length > 1 ? '.' + aValue[1] : '');
  3464. };
  3465. function fXSDateTime_normalize(oValue) {
  3466. return fXSDate_normalize(fXSTime_normalize(oValue));
  3467. };
  3468. //
  3469. fStaticContext_defineSystemDataType("dateTime", cXSDateTime);
  3470. /*
  3471. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3472. *
  3473. * Copyright (c) 2012 Sergey Ilinsky
  3474. * Dual licensed under the MIT and GPL licenses.
  3475. *
  3476. *
  3477. */
  3478. function cXSDecimal(nValue) {
  3479. this.value = nValue;
  3480. };
  3481. cXSDecimal.prototype = new cXSAnyAtomicType;
  3482. cXSDecimal.prototype.builtInKind = cXSConstants.DECIMAL_DT;
  3483. cXSDecimal.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_DECIMAL;
  3484. cXSDecimal.prototype.value = null;
  3485. cXSDecimal.prototype.valueOf = function() {
  3486. return this.value;
  3487. };
  3488. cXSDecimal.prototype.toString = function() {
  3489. return cString(this.value);
  3490. };
  3491. var rXSDecimal = /^[+\-]?((\d+(\.\d*)?)|(\.\d+))$/;
  3492. cXSDecimal.cast = function(vValue) {
  3493. if (vValue instanceof cXSDecimal)
  3494. return vValue;
  3495. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  3496. var aMatch = fString_trim(vValue).match(rXSDecimal);
  3497. if (aMatch)
  3498. return new cXSDecimal(+vValue);
  3499. throw new cException("FORG0001");
  3500. }
  3501. if (vValue instanceof cXSBoolean)
  3502. return new cXSDecimal(vValue * 1);
  3503. if (fXSAnyAtomicType_isNumeric(vValue)) {
  3504. if (!fIsNaN(vValue) && fIsFinite(vValue))
  3505. return new cXSDecimal(+vValue);
  3506. throw new cException("FOCA0002"
  3507. );
  3508. }
  3509. //
  3510. throw new cException("XPTY0004"
  3511. );
  3512. };
  3513. //
  3514. fStaticContext_defineSystemDataType("decimal", cXSDecimal);
  3515. /*
  3516. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3517. *
  3518. * Copyright (c) 2012 Sergey Ilinsky
  3519. * Dual licensed under the MIT and GPL licenses.
  3520. *
  3521. *
  3522. */
  3523. function cXSDouble(nValue) {
  3524. this.value = nValue;
  3525. };
  3526. cXSDouble.prototype = new cXSAnyAtomicType;
  3527. cXSDouble.prototype.builtInKind = cXSConstants.DOUBLE_DT;
  3528. cXSDouble.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_DOUBLE;
  3529. cXSDouble.prototype.value = null;
  3530. cXSDouble.prototype.valueOf = function() {
  3531. return this.value;
  3532. };
  3533. cXSDouble.prototype.toString = function() {
  3534. return cString(this.value);
  3535. };
  3536. var rXSDouble = /^([+\-]?((\d+(\.\d*)?)|(\.\d+))([eE][+\-]?\d+)?|(-?INF)|NaN)$/;
  3537. cXSDouble.cast = function(vValue) {
  3538. if (vValue instanceof cXSDouble)
  3539. return vValue;
  3540. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  3541. var aMatch = fString_trim(vValue).match(rXSDouble);
  3542. if (aMatch)
  3543. return new cXSDouble(aMatch[7] ? +aMatch[7].replace("INF", "Infinity") : +vValue);
  3544. throw new cException("FORG0001");
  3545. }
  3546. if (vValue instanceof cXSBoolean)
  3547. return new cXSDouble(vValue * 1);
  3548. if (fXSAnyAtomicType_isNumeric(vValue))
  3549. return new cXSDouble(vValue.value);
  3550. //
  3551. throw new cException("XPTY0004"
  3552. );
  3553. };
  3554. //
  3555. fStaticContext_defineSystemDataType("double", cXSDouble);
  3556. /*
  3557. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3558. *
  3559. * Copyright (c) 2012 Sergey Ilinsky
  3560. * Dual licensed under the MIT and GPL licenses.
  3561. *
  3562. *
  3563. */
  3564. function cXSDuration(nYear, nMonth, nDay, nHours, nMinutes, nSeconds, bNegative) {
  3565. this.year = nYear;
  3566. this.month = nMonth;
  3567. this.day = nDay;
  3568. this.hours = nHours;
  3569. this.minutes = nMinutes;
  3570. this.seconds = nSeconds;
  3571. this.negative = bNegative;
  3572. };
  3573. cXSDuration.prototype = new cXSAnyAtomicType;
  3574. cXSDuration.prototype.builtInKind = cXSConstants.DURATION_DT;
  3575. cXSDuration.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_DURATION;
  3576. cXSDuration.prototype.year = null;
  3577. cXSDuration.prototype.month = null;
  3578. cXSDuration.prototype.day = null;
  3579. cXSDuration.prototype.hours = null;
  3580. cXSDuration.prototype.minutes = null;
  3581. cXSDuration.prototype.seconds = null;
  3582. cXSDuration.prototype.negative = null;
  3583. cXSDuration.prototype.toString = function() {
  3584. return (this.negative ? '-' : '') + 'P'
  3585. + ((fXSDuration_getYearMonthComponent(this) + fXSDuration_getDayTimeComponent(this)) || 'T0S');
  3586. };
  3587. var rXSDuration = /^(-)?P(?:([0-9]+)Y)?(?:([0-9]+)M)?(?:([0-9]+)D)?(?:T(?:([0-9]+)H)?(?:([0-9]+)M)?(?:((?:(?:[0-9]+(?:.[0-9]*)?)|(?:.[0-9]+)))S)?)?$/;
  3588. cXSDuration.cast = function(vValue) {
  3589. if (vValue instanceof cXSDuration)
  3590. return vValue;
  3591. if (vValue instanceof cXSYearMonthDuration)
  3592. return new cXSDuration(vValue.year, vValue.month, 0, 0, 0, 0, vValue.negative);
  3593. if (vValue instanceof cXSDayTimeDuration)
  3594. return new cXSDuration(0, 0, vValue.day, vValue.hours, vValue.minutes, vValue.seconds, vValue.negative);
  3595. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  3596. var aMatch = fString_trim(vValue).match(rXSDuration);
  3597. if (aMatch)
  3598. return fXSDuration_normalize(new cXSDuration(+aMatch[2] || 0, +aMatch[3] || 0, +aMatch[4] || 0, +aMatch[5] || 0, +aMatch[6] || 0, +aMatch[7] || 0, aMatch[1] == '-'));
  3599. throw new cException("FORG0001");
  3600. }
  3601. //
  3602. throw new cException("XPTY0004"
  3603. );
  3604. };
  3605. // Utilities
  3606. function fXSDuration_getYearMonthComponent(oDuration) {
  3607. return (oDuration.year ? oDuration.year + 'Y' : '')
  3608. + (oDuration.month ? oDuration.month + 'M' : '');
  3609. };
  3610. function fXSDuration_getDayTimeComponent(oDuration) {
  3611. return (oDuration.day ? oDuration.day + 'D' : '')
  3612. + (oDuration.hours || oDuration.minutes || oDuration.seconds
  3613. ? 'T'
  3614. + (oDuration.hours ? oDuration.hours + 'H' : '')
  3615. + (oDuration.minutes ? oDuration.minutes + 'M' : '')
  3616. + (oDuration.seconds ? oDuration.seconds + 'S' : '')
  3617. : '');
  3618. };
  3619. function fXSDuration_normalize(oDuration) {
  3620. return fXSYearMonthDuration_normalize(fXSDayTimeDuration_normalize(oDuration));
  3621. };
  3622. //
  3623. fStaticContext_defineSystemDataType("duration", cXSDuration);
  3624. /*
  3625. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3626. *
  3627. * Copyright (c) 2012 Sergey Ilinsky
  3628. * Dual licensed under the MIT and GPL licenses.
  3629. *
  3630. *
  3631. */
  3632. function cXSFloat(nValue) {
  3633. this.value = nValue;
  3634. };
  3635. cXSFloat.prototype = new cXSAnyAtomicType;
  3636. cXSFloat.prototype.builtInKind = cXSConstants.FLOAT_DT;
  3637. cXSFloat.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_FLOAT;
  3638. cXSFloat.prototype.value = null;
  3639. cXSFloat.prototype.valueOf = function() {
  3640. return this.value;
  3641. };
  3642. cXSFloat.prototype.toString = function() {
  3643. return cString(this.value);
  3644. };
  3645. var rXSFloat = /^([+\-]?((\d+(\.\d*)?)|(\.\d+))([eE][+\-]?\d+)?|(-?INF)|NaN)$/;
  3646. cXSFloat.cast = function(vValue) {
  3647. if (vValue instanceof cXSFloat)
  3648. return vValue;
  3649. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  3650. var aMatch = fString_trim(vValue).match(rXSFloat);
  3651. if (aMatch)
  3652. return new cXSFloat(aMatch[7] ? +aMatch[7].replace("INF", "Infinity") : +vValue);
  3653. throw new cException("FORG0001");
  3654. }
  3655. if (vValue instanceof cXSBoolean)
  3656. return new cXSFloat(vValue * 1);
  3657. if (fXSAnyAtomicType_isNumeric(vValue))
  3658. return new cXSFloat(vValue.value);
  3659. //
  3660. throw new cException("XPTY0004"
  3661. );
  3662. };
  3663. //
  3664. fStaticContext_defineSystemDataType("float", cXSFloat);
  3665. /*
  3666. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3667. *
  3668. * Copyright (c) 2012 Sergey Ilinsky
  3669. * Dual licensed under the MIT and GPL licenses.
  3670. *
  3671. *
  3672. */
  3673. function cXSGDay(nDay, nTimezone) {
  3674. this.day = nDay;
  3675. this.timezone = nTimezone;
  3676. };
  3677. cXSGDay.prototype = new cXSAnyAtomicType;
  3678. cXSGDay.prototype.builtInKind = cXSConstants.GDAY_DT;
  3679. cXSGDay.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_GDAY;
  3680. cXSGDay.prototype.day = null;
  3681. cXSGDay.prototype.timezone = null;
  3682. cXSGDay.prototype.toString = function() {
  3683. return '-'
  3684. + '-'
  3685. + '-' + fXSDateTime_pad(this.day)
  3686. + fXSDateTime_getTZComponent(this);
  3687. };
  3688. var rXSGDay = /^---(0[1-9]|[12]\d|3[01])(Z|([+\-])(0\d|1[0-4]):([0-5]\d))?$/;
  3689. cXSGDay.cast = function(vValue) {
  3690. if (vValue instanceof cXSGDay)
  3691. return vValue;
  3692. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  3693. var aMatch = fString_trim(vValue).match(rXSGDay);
  3694. if (aMatch) {
  3695. var nDay = +aMatch[1];
  3696. return new cXSGDay( nDay,
  3697. aMatch[2] ? aMatch[2] == 'Z' ? 0 : (aMatch[3] == '-' ? -1 : 1) * (aMatch[4] * 60 + aMatch[5] * 1) : null
  3698. );
  3699. }
  3700. throw new cException("FORG0001");
  3701. }
  3702. if (vValue instanceof cXSDate || vValue instanceof cXSDateTime)
  3703. return new cXSGDay(vValue.day, vValue.timezone);
  3704. //
  3705. throw new cException("XPTY0004"
  3706. );
  3707. };
  3708. //
  3709. fStaticContext_defineSystemDataType("gDay", cXSGDay);
  3710. /*
  3711. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3712. *
  3713. * Copyright (c) 2012 Sergey Ilinsky
  3714. * Dual licensed under the MIT and GPL licenses.
  3715. *
  3716. *
  3717. */
  3718. function cXSGMonth(nMonth, nTimezone) {
  3719. this.month = nMonth;
  3720. this.timezone = nTimezone;
  3721. };
  3722. cXSGMonth.prototype = new cXSAnyAtomicType;
  3723. cXSGMonth.prototype.builtInKind = cXSConstants.GMONTH_DT;
  3724. cXSGMonth.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_GMONTH;
  3725. cXSGMonth.prototype.month = null;
  3726. cXSGMonth.prototype.timezone = null;
  3727. cXSGMonth.prototype.toString = function() {
  3728. return '-'
  3729. + '-' + fXSDateTime_pad(this.month)
  3730. + fXSDateTime_getTZComponent(this);
  3731. };
  3732. var rXSGMonth = /^--(0[1-9]|1[0-2])(Z|([+\-])(0\d|1[0-4]):([0-5]\d))?$/;
  3733. cXSGMonth.cast = function(vValue) {
  3734. if (vValue instanceof cXSGMonth)
  3735. return vValue;
  3736. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  3737. var aMatch = fString_trim(vValue).match(rXSGMonth);
  3738. if (aMatch) {
  3739. var nMonth = +aMatch[1];
  3740. return new cXSGMonth( nMonth,
  3741. aMatch[2] ? aMatch[2] == 'Z' ? 0 : (aMatch[3] == '-' ? -1 : 1) * (aMatch[4] * 60 + aMatch[5] * 1) : null
  3742. );
  3743. }
  3744. throw new cException("FORG0001");
  3745. }
  3746. if (vValue instanceof cXSDate || vValue instanceof cXSDateTime)
  3747. return new cXSGMonth(vValue.month, vValue.timezone);
  3748. //
  3749. throw new cException("XPTY0004"
  3750. );
  3751. };
  3752. //
  3753. fStaticContext_defineSystemDataType("gMonth", cXSGMonth);
  3754. /*
  3755. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3756. *
  3757. * Copyright (c) 2012 Sergey Ilinsky
  3758. * Dual licensed under the MIT and GPL licenses.
  3759. *
  3760. *
  3761. */
  3762. function cXSGMonthDay(nMonth, nDay, nTimezone) {
  3763. this.month = nMonth;
  3764. this.day = nDay;
  3765. this.timezone = nTimezone;
  3766. };
  3767. cXSGMonthDay.prototype = new cXSAnyAtomicType;
  3768. cXSGMonthDay.prototype.builtInKind = cXSConstants.GMONTHDAY_DT;
  3769. cXSGMonthDay.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_GMONTHDAY;
  3770. cXSGMonthDay.prototype.month = null;
  3771. cXSGMonthDay.prototype.day = null;
  3772. cXSGMonthDay.prototype.timezone = null;
  3773. cXSGMonthDay.prototype.toString = function() {
  3774. return '-'
  3775. + '-' + fXSDateTime_pad(this.month)
  3776. + '-' + fXSDateTime_pad(this.day)
  3777. + fXSDateTime_getTZComponent(this);
  3778. };
  3779. var rXSGMonthDay = /^--(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])(Z|([+\-])(0\d|1[0-4]):([0-5]\d))?$/;
  3780. cXSGMonthDay.cast = function(vValue) {
  3781. if (vValue instanceof cXSGMonthDay)
  3782. return vValue;
  3783. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  3784. var aMatch = fString_trim(vValue).match(rXSGMonthDay);
  3785. if (aMatch) {
  3786. var nMonth = +aMatch[1],
  3787. nDay = +aMatch[2];
  3788. if (nDay - 1 < fXSDate_getDaysForYearMonth(1976, nMonth))
  3789. return new cXSGMonthDay( nMonth,
  3790. nDay,
  3791. aMatch[3] ? aMatch[3] == 'Z' ? 0 : (aMatch[4] == '-' ? -1 : 1) * (aMatch[5] * 60 + aMatch[6] * 1) : null
  3792. );
  3793. //
  3794. throw new cException("FORG0001"
  3795. );
  3796. }
  3797. throw new cException("FORG0001");
  3798. }
  3799. if (vValue instanceof cXSDate || vValue instanceof cXSDateTime)
  3800. return new cXSGMonthDay(vValue.month, vValue.day, vValue.timezone);
  3801. //
  3802. throw new cException("XPTY0004"
  3803. );
  3804. };
  3805. //
  3806. fStaticContext_defineSystemDataType("gMonthDay", cXSGMonthDay);
  3807. /*
  3808. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3809. *
  3810. * Copyright (c) 2012 Sergey Ilinsky
  3811. * Dual licensed under the MIT and GPL licenses.
  3812. *
  3813. *
  3814. */
  3815. function cXSGYear(nYear, nTimezone) {
  3816. this.year = nYear;
  3817. this.timezone = nTimezone;
  3818. };
  3819. cXSGYear.prototype = new cXSAnyAtomicType;
  3820. cXSGYear.prototype.builtInKind = cXSConstants.GYEAR_DT;
  3821. cXSGYear.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_GYEAR;
  3822. cXSGYear.prototype.year = null;
  3823. cXSGYear.prototype.timezone = null;
  3824. cXSGYear.prototype.toString = function() {
  3825. return fXSDateTime_pad(this.year)
  3826. + fXSDateTime_getTZComponent(this);
  3827. };
  3828. var rXSGYear = /^-?([1-9]\d\d\d+|0\d\d\d)(Z|([+\-])(0\d|1[0-4]):([0-5]\d))?$/;
  3829. cXSGYear.cast = function(vValue) {
  3830. if (vValue instanceof cXSGYear)
  3831. return vValue;
  3832. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  3833. var aMatch = fString_trim(vValue).match(rXSGYear);
  3834. if (aMatch) {
  3835. var nYear = +aMatch[1];
  3836. return new cXSGYear( nYear,
  3837. aMatch[2] ? aMatch[2] == 'Z' ? 0 : (aMatch[3] == '-' ? -1 : 1) * (aMatch[4] * 60 + aMatch[5] * 1) : null
  3838. );
  3839. }
  3840. throw new cException("FORG0001");
  3841. }
  3842. if (vValue instanceof cXSDate || vValue instanceof cXSDateTime)
  3843. return new cXSGYear(vValue.year, vValue.timezone);
  3844. //
  3845. throw new cException("XPTY0004"
  3846. );
  3847. };
  3848. //
  3849. fStaticContext_defineSystemDataType("gYear", cXSGYear);
  3850. /*
  3851. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3852. *
  3853. * Copyright (c) 2012 Sergey Ilinsky
  3854. * Dual licensed under the MIT and GPL licenses.
  3855. *
  3856. *
  3857. */
  3858. function cXSGYearMonth(nYear, nMonth, nTimezone) {
  3859. this.year = nYear;
  3860. this.month = nMonth;
  3861. this.timezone = nTimezone;
  3862. };
  3863. cXSGYearMonth.prototype = new cXSAnyAtomicType;
  3864. cXSGYearMonth.prototype.builtInKind = cXSConstants.GYEARMONTH_DT;
  3865. cXSGYearMonth.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_GYEARMONTH;
  3866. cXSGYearMonth.prototype.year = null;
  3867. cXSGYearMonth.prototype.month = null;
  3868. cXSGYearMonth.prototype.timezone= null;
  3869. cXSGYearMonth.prototype.toString = function() {
  3870. return fXSDateTime_pad(this.year)
  3871. + '-' + fXSDateTime_pad(this.month)
  3872. + fXSDateTime_getTZComponent(this);
  3873. };
  3874. var rXSGYearMonth = /^-?([1-9]\d\d\d+|0\d\d\d)-(0[1-9]|1[0-2])(Z|([+\-])(0\d|1[0-4]):([0-5]\d))?$/;
  3875. cXSGYearMonth.cast = function(vValue) {
  3876. if (vValue instanceof cXSGYearMonth)
  3877. return vValue;
  3878. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  3879. var aMatch = fString_trim(vValue).match(rXSGYearMonth);
  3880. if (aMatch) {
  3881. var nYear = +aMatch[1],
  3882. nMonth = +aMatch[2];
  3883. return new cXSGYearMonth( nYear,
  3884. nMonth,
  3885. aMatch[3] ? aMatch[3] == 'Z' ? 0 : (aMatch[4] == '-' ? -1 : 1) * (aMatch[5] * 60 + aMatch[6] * 1) : null
  3886. );
  3887. }
  3888. throw new cException("FORG0001");
  3889. }
  3890. if (vValue instanceof cXSDate || vValue instanceof cXSDateTime)
  3891. return new cXSGYearMonth(vValue.year, vValue.month, vValue.timezone);
  3892. //
  3893. throw new cException("XPTY0004"
  3894. );
  3895. };
  3896. //
  3897. fStaticContext_defineSystemDataType("gYearMonth", cXSGYearMonth);
  3898. /*
  3899. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3900. *
  3901. * Copyright (c) 2012 Sergey Ilinsky
  3902. * Dual licensed under the MIT and GPL licenses.
  3903. *
  3904. *
  3905. */
  3906. function cXSHexBinary(sValue) {
  3907. this.value = sValue;
  3908. };
  3909. cXSHexBinary.prototype = new cXSAnyAtomicType;
  3910. cXSHexBinary.prototype.builtInKind = cXSConstants.HEXBINARY_DT;
  3911. cXSHexBinary.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_HEXBINARY;
  3912. cXSHexBinary.prototype.value = null;
  3913. cXSHexBinary.prototype.valueOf = function() {
  3914. return this.value;
  3915. };
  3916. cXSHexBinary.prototype.toString = function() {
  3917. return this.value;
  3918. };
  3919. var rXSHexBinary = /^([0-9a-fA-F]{2})*$/;
  3920. cXSHexBinary.cast = function(vValue) {
  3921. if (vValue instanceof cXSHexBinary)
  3922. return vValue;
  3923. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  3924. var aMatch = fString_trim(vValue).match(rXSHexBinary);
  3925. if (aMatch)
  3926. return new cXSHexBinary(aMatch[0].toUpperCase());
  3927. throw new cException("FORG0001");
  3928. }
  3929. if (vValue instanceof cXSBase64Binary) {
  3930. var sValue = fWindow_atob(vValue.valueOf()),
  3931. aValue = [];
  3932. for (var nIndex = 0, nLength = sValue.length, sLetter; nIndex < nLength; nIndex++) {
  3933. sLetter = sValue.charCodeAt(nIndex).toString(16);
  3934. aValue.push(new cArray(3 - sLetter.length).join('0') + sLetter);
  3935. }
  3936. return new cXSHexBinary(aValue.join(''));
  3937. }
  3938. //
  3939. throw new cException("XPTY0004"
  3940. );
  3941. };
  3942. //
  3943. fStaticContext_defineSystemDataType("hexBinary", cXSHexBinary);
  3944. /*
  3945. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3946. *
  3947. * Copyright (c) 2012 Sergey Ilinsky
  3948. * Dual licensed under the MIT and GPL licenses.
  3949. *
  3950. *
  3951. */
  3952. function cXSNOTATION() {
  3953. };
  3954. cXSNOTATION.prototype = new cXSAnyAtomicType;
  3955. cXSNOTATION.prototype.builtInKind = cXSConstants.NOTATION_DT;
  3956. cXSNOTATION.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_NOTATION;
  3957. cXSNOTATION.cast = function(vValue) {
  3958. throw new cException("XPST0017"
  3959. ); // {http://www.w3.org/2001/XMLSchema}NOTATION
  3960. };
  3961. //
  3962. fStaticContext_defineSystemDataType("NOTATION", cXSNOTATION);
  3963. /*
  3964. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  3965. *
  3966. * Copyright (c) 2012 Sergey Ilinsky
  3967. * Dual licensed under the MIT and GPL licenses.
  3968. *
  3969. *
  3970. */
  3971. function cXSQName(sPrefix, sLocalName, sNameSpaceURI) {
  3972. this.prefix = sPrefix;
  3973. this.localName = sLocalName;
  3974. this.namespaceURI = sNameSpaceURI;
  3975. };
  3976. cXSQName.prototype = new cXSAnyAtomicType;
  3977. cXSQName.prototype.builtInKind = cXSConstants.QNAME_DT;
  3978. cXSQName.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_QNAME;
  3979. cXSQName.prototype.prefix = null;
  3980. cXSQName.prototype.localName = null;
  3981. cXSQName.prototype.namespaceURI = null;
  3982. cXSQName.prototype.toString = function() {
  3983. return (this.prefix ? this.prefix + ':' : '') + this.localName;
  3984. };
  3985. var rXSQName = /^(?:(?![0-9-])(\w[\w.-]*)\:)?(?![0-9-])(\w[\w.-]*)$/;
  3986. cXSQName.cast = function(vValue) {
  3987. if (vValue instanceof cXSQName)
  3988. return vValue;
  3989. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  3990. var aMatch = fString_trim(vValue).match(rXSQName);
  3991. if (aMatch)
  3992. return new cXSQName(aMatch[1] || null, aMatch[2], null);
  3993. throw new cException("FORG0001");
  3994. }
  3995. //
  3996. throw new cException("XPTY0004"
  3997. );
  3998. };
  3999. //
  4000. fStaticContext_defineSystemDataType("QName", cXSQName);
  4001. /*
  4002. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4003. *
  4004. * Copyright (c) 2012 Sergey Ilinsky
  4005. * Dual licensed under the MIT and GPL licenses.
  4006. *
  4007. *
  4008. */
  4009. function cXSString(sValue) {
  4010. this.value = sValue;
  4011. };
  4012. cXSString.prototype = new cXSAnyAtomicType;
  4013. cXSString.prototype.value = null;
  4014. cXSString.prototype.builtInKind = cXSConstants.STRING_DT;
  4015. cXSString.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_STRING;
  4016. cXSString.prototype.valueOf = function() {
  4017. return this.value;
  4018. };
  4019. cXSString.prototype.toString = function() {
  4020. return this.value;
  4021. };
  4022. cXSString.cast = function(vValue) {
  4023. return new cXSString(cString(vValue));
  4024. //
  4025. throw new cException("XPTY0004"
  4026. );
  4027. };
  4028. //
  4029. fStaticContext_defineSystemDataType("string", cXSString);
  4030. /*
  4031. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4032. *
  4033. * Copyright (c) 2012 Sergey Ilinsky
  4034. * Dual licensed under the MIT and GPL licenses.
  4035. *
  4036. *
  4037. */
  4038. function cXSTime(nHours, nMinutes, nSeconds, nTimezone) {
  4039. this.hours = nHours;
  4040. this.minutes = nMinutes;
  4041. this.seconds = nSeconds;
  4042. this.timezone = nTimezone;
  4043. };
  4044. cXSTime.prototype = new cXSAnyAtomicType;
  4045. cXSTime.prototype.builtInKind = cXSConstants.TIME_DT;
  4046. cXSTime.prototype.primitiveKind = cXSAnySimpleType.PRIMITIVE_TIME;
  4047. cXSTime.prototype.hours = null;
  4048. cXSTime.prototype.minutes = null;
  4049. cXSTime.prototype.seconds = null;
  4050. cXSTime.prototype.timezone = null;
  4051. cXSTime.prototype.toString = function() {
  4052. return fXSDateTime_getTimeComponent(this)
  4053. + fXSDateTime_getTZComponent(this);
  4054. };
  4055. var rXSTime = /^(([01]\d|2[0-3]):([0-5]\d):([0-5]\d)(?:\.(\d+))?|(24:00:00)(?:\.(0+))?)(Z|([+\-])(0\d|1[0-4]):([0-5]\d))?$/;
  4056. cXSTime.cast = function(vValue) {
  4057. if (vValue instanceof cXSTime)
  4058. return vValue;
  4059. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  4060. var aMatch = fString_trim(vValue).match(rXSTime);
  4061. if (aMatch) {
  4062. var bValue = !!aMatch[6];
  4063. return new cXSTime(bValue ? 0 : +aMatch[2],
  4064. bValue ? 0 : +aMatch[3],
  4065. cNumber((bValue ? 0 : aMatch[4]) + '.' + (bValue ? 0 : aMatch[5] || 0)),
  4066. aMatch[8] ? aMatch[8] == 'Z' ? 0 : (aMatch[9] == '-' ? -1 : 1) * (aMatch[10] * 60 + aMatch[11] * 1) : null
  4067. );
  4068. }
  4069. throw new cException("FORG0001");
  4070. }
  4071. if (vValue instanceof cXSDateTime)
  4072. return new cXSTime(vValue.hours, vValue.minutes, vValue.seconds, vValue.timezone);
  4073. //
  4074. throw new cException("XPTY0004"
  4075. );
  4076. };
  4077. //
  4078. function fXSTime_normalize(oValue) {
  4079. //
  4080. if (oValue.seconds >= 60 || oValue.seconds < 0) {
  4081. oValue.minutes += ~~(oValue.seconds / 60) - (oValue.seconds < 0 && oValue.seconds % 60 ? 1 : 0);
  4082. oValue.seconds = oValue.seconds % 60 + (oValue.seconds < 0 && oValue.seconds % 60 ? 60 : 0);
  4083. }
  4084. //
  4085. if (oValue.minutes >= 60 || oValue.minutes < 0) {
  4086. oValue.hours += ~~(oValue.minutes / 60) - (oValue.minutes < 0 && oValue.minutes % 60 ? 1 : 0);
  4087. oValue.minutes = oValue.minutes % 60 + (oValue.minutes < 0 && oValue.minutes % 60 ? 60 : 0);
  4088. }
  4089. //
  4090. if (oValue.hours >= 24 || oValue.hours < 0) {
  4091. if (oValue instanceof cXSDateTime)
  4092. oValue.day += ~~(oValue.hours / 24) - (oValue.hours < 0 && oValue.hours % 24 ? 1 : 0);
  4093. oValue.hours = oValue.hours % 24 + (oValue.hours < 0 && oValue.hours % 24 ? 24 : 0);
  4094. }
  4095. //
  4096. return oValue;
  4097. };
  4098. //
  4099. fStaticContext_defineSystemDataType("time", cXSTime);
  4100. /*
  4101. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4102. *
  4103. * Copyright (c) 2012 Sergey Ilinsky
  4104. * Dual licensed under the MIT and GPL licenses.
  4105. *
  4106. *
  4107. */
  4108. function cXSUntypedAtomic(sValue) {
  4109. this.value = sValue;
  4110. };
  4111. cXSUntypedAtomic.prototype = new cXSAnyAtomicType;
  4112. cXSUntypedAtomic.prototype.builtInKind = cXSConstants.XT_UNTYPEDATOMIC_DT;
  4113. cXSUntypedAtomic.prototype.toString = function() {
  4114. return cString(this.value);
  4115. };
  4116. cXSUntypedAtomic.cast = function(vValue) {
  4117. if (vValue instanceof cXSUntypedAtomic)
  4118. return vValue;
  4119. return new cXSUntypedAtomic(cString(vValue));
  4120. //
  4121. throw new cException("XPTY0004"
  4122. );
  4123. };
  4124. //
  4125. fStaticContext_defineSystemDataType("untypedAtomic", cXSUntypedAtomic);
  4126. /*
  4127. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4128. *
  4129. * Copyright (c) 2012 Sergey Ilinsky
  4130. * Dual licensed under the MIT and GPL licenses.
  4131. *
  4132. *
  4133. */
  4134. function cXSYearMonthDuration(nYear, nMonth, bNegative) {
  4135. cXSDuration.call(this, nYear, nMonth, 0, 0, 0, 0, bNegative);
  4136. };
  4137. cXSYearMonthDuration.prototype = new cXSDuration;
  4138. cXSYearMonthDuration.prototype.builtInKind = cXSConstants.XT_YEARMONTHDURATION_DT;
  4139. cXSYearMonthDuration.prototype.toString = function() {
  4140. return (this.negative ? '-' : '') + 'P'
  4141. + (fXSDuration_getYearMonthComponent(this) || '0M');
  4142. };
  4143. var rXSYearMonthDuration = /^(-)?P(?:([0-9]+)Y)?(?:([0-9]+)M)?$/;
  4144. cXSYearMonthDuration.cast = function(vValue) {
  4145. if (vValue instanceof cXSYearMonthDuration)
  4146. return vValue;
  4147. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  4148. var aMatch = fString_trim(vValue).match(rXSYearMonthDuration);
  4149. if (aMatch)
  4150. return fXSYearMonthDuration_normalize(new cXSYearMonthDuration(+aMatch[2] || 0, +aMatch[3] || 0, aMatch[1] == '-'));
  4151. throw new cException("FORG0001");
  4152. }
  4153. if (vValue instanceof cXSDayTimeDuration)
  4154. return new cXSYearMonthDuration(0, 0);
  4155. if (vValue instanceof cXSDuration)
  4156. return new cXSYearMonthDuration(vValue.year, vValue.month, vValue.negative);
  4157. //
  4158. throw new cException("XPTY0004"
  4159. );
  4160. };
  4161. //
  4162. function fXSYearMonthDuration_normalize(oDuration) {
  4163. if (oDuration.month >= 12) {
  4164. oDuration.year += ~~(oDuration.month / 12);
  4165. oDuration.month %= 12;
  4166. }
  4167. return oDuration;
  4168. };
  4169. //
  4170. fStaticContext_defineSystemDataType("yearMonthDuration", cXSYearMonthDuration);
  4171. /*
  4172. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4173. *
  4174. * Copyright (c) 2012 Sergey Ilinsky
  4175. * Dual licensed under the MIT and GPL licenses.
  4176. *
  4177. *
  4178. */
  4179. function cXSDayTimeDuration(nDay, nHours, nMinutes, nSeconds, bNegative) {
  4180. cXSDuration.call(this, 0, 0, nDay, nHours, nMinutes, nSeconds, bNegative);
  4181. };
  4182. cXSDayTimeDuration.prototype = new cXSDuration;
  4183. cXSDayTimeDuration.prototype.builtInKind = cXSConstants.DAYTIMEDURATION_DT;
  4184. cXSDayTimeDuration.prototype.toString = function() {
  4185. return (this.negative ? '-' : '') + 'P'
  4186. + (fXSDuration_getDayTimeComponent(this) || 'T0S');
  4187. };
  4188. var rXSDayTimeDuration = /^(-)?P(?:([0-9]+)D)?(?:T(?:([0-9]+)H)?(?:([0-9]+)M)?(?:((?:(?:[0-9]+(?:.[0-9]*)?)|(?:.[0-9]+)))S)?)?$/;
  4189. cXSDayTimeDuration.cast = function(vValue) {
  4190. if (vValue instanceof cXSDayTimeDuration)
  4191. return vValue;
  4192. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  4193. var aMatch = fString_trim(vValue).match(rXSDayTimeDuration);
  4194. if (aMatch)
  4195. return fXSDayTimeDuration_normalize(new cXSDayTimeDuration(+aMatch[2] || 0, +aMatch[3] || 0, +aMatch[4] || 0, +aMatch[5] || 0, aMatch[1] == '-'));
  4196. throw new cException("FORG0001");
  4197. }
  4198. if (vValue instanceof cXSYearMonthDuration)
  4199. return new cXSDayTimeDuration(0, 0, 0, 0);
  4200. if (vValue instanceof cXSDuration)
  4201. return new cXSDayTimeDuration(vValue.day, vValue.hours, vValue.minutes, vValue.seconds, vValue.negative);
  4202. //
  4203. throw new cException("XPTY0004"
  4204. );
  4205. };
  4206. // Utilities
  4207. function fXSDayTimeDuration_normalize(oDuration) {
  4208. if (oDuration.seconds >= 60) {
  4209. oDuration.minutes += ~~(oDuration.seconds / 60);
  4210. oDuration.seconds %= 60;
  4211. }
  4212. if (oDuration.minutes >= 60) {
  4213. oDuration.hours += ~~(oDuration.minutes / 60);
  4214. oDuration.minutes %= 60;
  4215. }
  4216. if (oDuration.hours >= 24) {
  4217. oDuration.day += ~~(oDuration.hours / 24);
  4218. oDuration.hours %= 24;
  4219. }
  4220. return oDuration;
  4221. };
  4222. //
  4223. fStaticContext_defineSystemDataType("dayTimeDuration", cXSDayTimeDuration);
  4224. /*
  4225. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4226. *
  4227. * Copyright (c) 2012 Sergey Ilinsky
  4228. * Dual licensed under the MIT and GPL licenses.
  4229. *
  4230. *
  4231. */
  4232. function cXSInteger(nValue) {
  4233. this.value = nValue;
  4234. };
  4235. cXSInteger.prototype = new cXSDecimal;
  4236. cXSInteger.prototype.builtInKind = cXSConstants.INTEGER_DT;
  4237. var rXSInteger = /^[-+]?[0-9]+$/;
  4238. cXSInteger.cast = function(vValue) {
  4239. if (vValue instanceof cXSInteger)
  4240. return new cXSInteger(vValue.value);
  4241. if (vValue instanceof cXSString || vValue instanceof cXSUntypedAtomic) {
  4242. var aMatch = fString_trim(vValue).match(rXSInteger);
  4243. if (aMatch)
  4244. return new cXSInteger(+vValue);
  4245. throw new cException("FORG0001");
  4246. }
  4247. if (vValue instanceof cXSBoolean)
  4248. return new cXSInteger(vValue * 1);
  4249. if (fXSAnyAtomicType_isNumeric(vValue)) {
  4250. if (!fIsNaN(vValue) && fIsFinite(vValue))
  4251. return new cXSInteger(+vValue);
  4252. throw new cException("FOCA0002"
  4253. );
  4254. }
  4255. //
  4256. throw new cException("XPTY0004"
  4257. );
  4258. };
  4259. //
  4260. fStaticContext_defineSystemDataType("integer", cXSInteger);
  4261. /*
  4262. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4263. *
  4264. * Copyright (c) 2012 Sergey Ilinsky
  4265. * Dual licensed under the MIT and GPL licenses.
  4266. *
  4267. *
  4268. */
  4269. function cXSNonPositiveInteger(nValue) {
  4270. this.value = nValue;
  4271. };
  4272. cXSNonPositiveInteger.prototype = new cXSInteger;
  4273. cXSNonPositiveInteger.prototype.builtInKind = cXSConstants.NONPOSITIVEINTEGER_DT;
  4274. cXSNonPositiveInteger.cast = function(vValue) {
  4275. var oValue;
  4276. try {
  4277. oValue = cXSInteger.cast(vValue);
  4278. }
  4279. catch (oError) {
  4280. throw oError;
  4281. }
  4282. // facet validation
  4283. if (oValue.value <= 0)
  4284. return new cXSNonPositiveInteger(oValue.value);
  4285. //
  4286. throw new cException("FORG0001");
  4287. };
  4288. //
  4289. fStaticContext_defineSystemDataType("nonPositiveInteger", cXSNonPositiveInteger);
  4290. /*
  4291. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4292. *
  4293. * Copyright (c) 2012 Sergey Ilinsky
  4294. * Dual licensed under the MIT and GPL licenses.
  4295. *
  4296. *
  4297. */
  4298. function cXSNegativeInteger(nValue) {
  4299. this.value = nValue;
  4300. };
  4301. cXSNegativeInteger.prototype = new cXSNonPositiveInteger;
  4302. cXSNegativeInteger.prototype.builtInKind = cXSConstants.NEGATIVEINTEGER_DT;
  4303. cXSNegativeInteger.cast = function(vValue) {
  4304. var oValue;
  4305. try {
  4306. oValue = cXSInteger.cast(vValue);
  4307. }
  4308. catch (oError) {
  4309. throw oError;
  4310. }
  4311. // facet validation
  4312. if (oValue.value <= -1)
  4313. return new cXSNegativeInteger(oValue.value);
  4314. //
  4315. throw new cException("FORG0001");
  4316. };
  4317. //
  4318. fStaticContext_defineSystemDataType("negativeInteger", cXSNegativeInteger);
  4319. /*
  4320. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4321. *
  4322. * Copyright (c) 2012 Sergey Ilinsky
  4323. * Dual licensed under the MIT and GPL licenses.
  4324. *
  4325. *
  4326. */
  4327. function cXSLong(nValue) {
  4328. this.value = nValue;
  4329. };
  4330. cXSLong.prototype = new cXSInteger;
  4331. cXSLong.prototype.builtInKind = cXSConstants.LONG_DT;
  4332. cXSLong.cast = function(vValue) {
  4333. var oValue;
  4334. try {
  4335. oValue = cXSInteger.cast(vValue);
  4336. }
  4337. catch (oError) {
  4338. throw oError;
  4339. }
  4340. // facet validation
  4341. if (oValue.value <= 9223372036854775807 && oValue.value >= -9223372036854775808)
  4342. return new cXSLong(oValue.value);
  4343. //
  4344. throw new cException("FORG0001");
  4345. };
  4346. //
  4347. fStaticContext_defineSystemDataType("long", cXSLong);
  4348. /*
  4349. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4350. *
  4351. * Copyright (c) 2012 Sergey Ilinsky
  4352. * Dual licensed under the MIT and GPL licenses.
  4353. *
  4354. *
  4355. */
  4356. function cXSInt(nValue) {
  4357. this.value = nValue;
  4358. };
  4359. cXSInt.prototype = new cXSLong;
  4360. cXSInt.prototype.builtInKind = cXSConstants.INT_DT;
  4361. cXSInt.cast = function(vValue) {
  4362. var oValue;
  4363. try {
  4364. oValue = cXSInteger.cast(vValue);
  4365. }
  4366. catch (oError) {
  4367. throw oError;
  4368. }
  4369. // facet validation
  4370. if (oValue.value <= 2147483647 && oValue.value >= -2147483648)
  4371. return new cXSInt(oValue.value);
  4372. //
  4373. throw new cException("FORG0001");
  4374. };
  4375. //
  4376. fStaticContext_defineSystemDataType("int", cXSInt);
  4377. /*
  4378. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4379. *
  4380. * Copyright (c) 2012 Sergey Ilinsky
  4381. * Dual licensed under the MIT and GPL licenses.
  4382. *
  4383. *
  4384. */
  4385. function cXSShort(nValue) {
  4386. this.value = nValue;
  4387. };
  4388. cXSShort.prototype = new cXSInt;
  4389. cXSShort.prototype.builtInKind = cXSConstants.SHORT_DT;
  4390. cXSShort.cast = function(vValue) {
  4391. var oValue;
  4392. try {
  4393. oValue = cXSInteger.cast(vValue);
  4394. }
  4395. catch (oError) {
  4396. throw oError;
  4397. }
  4398. // facet validation
  4399. if (oValue.value <= 32767 && oValue.value >= -32768)
  4400. return new cXSShort(oValue.value);
  4401. //
  4402. throw new cException("FORG0001");
  4403. };
  4404. //
  4405. fStaticContext_defineSystemDataType("short", cXSShort);
  4406. /*
  4407. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4408. *
  4409. * Copyright (c) 2012 Sergey Ilinsky
  4410. * Dual licensed under the MIT and GPL licenses.
  4411. *
  4412. *
  4413. */
  4414. function cXSByte(nValue) {
  4415. this.value = nValue;
  4416. };
  4417. cXSByte.prototype = new cXSShort;
  4418. cXSByte.prototype.builtInKind = cXSConstants.BYTE_DT;
  4419. cXSByte.cast = function(vValue) {
  4420. var oValue;
  4421. try {
  4422. oValue = cXSInteger.cast(vValue);
  4423. }
  4424. catch (oError) {
  4425. throw oError;
  4426. }
  4427. // facet validation
  4428. if (oValue.value <= 127 && oValue.value >= -128)
  4429. return new cXSByte(oValue.value);
  4430. //
  4431. throw new cException("FORG0001");
  4432. };
  4433. //
  4434. fStaticContext_defineSystemDataType("byte", cXSByte);
  4435. /*
  4436. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4437. *
  4438. * Copyright (c) 2012 Sergey Ilinsky
  4439. * Dual licensed under the MIT and GPL licenses.
  4440. *
  4441. *
  4442. */
  4443. function cXSNonNegativeInteger(nValue) {
  4444. this.value = nValue;
  4445. };
  4446. cXSNonNegativeInteger.prototype = new cXSInteger;
  4447. cXSNonNegativeInteger.prototype.builtInKind = cXSConstants.NONNEGATIVEINTEGER_DT;
  4448. cXSNonNegativeInteger.cast = function(vValue) {
  4449. var oValue;
  4450. try {
  4451. oValue = cXSInteger.cast(vValue);
  4452. }
  4453. catch (oError) {
  4454. throw oError;
  4455. }
  4456. // facet validation
  4457. if (oValue.value >= 0)
  4458. return new cXSNonNegativeInteger(oValue.value);
  4459. //
  4460. throw new cException("FORG0001");
  4461. };
  4462. //
  4463. fStaticContext_defineSystemDataType("nonNegativeInteger", cXSNonNegativeInteger);
  4464. /*
  4465. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4466. *
  4467. * Copyright (c) 2012 Sergey Ilinsky
  4468. * Dual licensed under the MIT and GPL licenses.
  4469. *
  4470. *
  4471. */
  4472. function cXSPositiveInteger(nValue) {
  4473. this.value = nValue;
  4474. };
  4475. cXSPositiveInteger.prototype = new cXSNonNegativeInteger;
  4476. cXSPositiveInteger.prototype.builtInKind = cXSConstants.POSITIVEINTEGER_DT;
  4477. cXSPositiveInteger.cast = function(vValue) {
  4478. var oValue;
  4479. try {
  4480. oValue = cXSInteger.cast(vValue);
  4481. }
  4482. catch (oError) {
  4483. throw oError;
  4484. }
  4485. // facet validation
  4486. if (oValue.value >= 1)
  4487. return new cXSPositiveInteger(oValue.value);
  4488. //
  4489. throw new cException("FORG0001");
  4490. };
  4491. //
  4492. fStaticContext_defineSystemDataType("positiveInteger", cXSPositiveInteger);
  4493. /*
  4494. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4495. *
  4496. * Copyright (c) 2012 Sergey Ilinsky
  4497. * Dual licensed under the MIT and GPL licenses.
  4498. *
  4499. *
  4500. */
  4501. function cXSUnsignedLong(nValue) {
  4502. this.value = nValue;
  4503. };
  4504. cXSUnsignedLong.prototype = new cXSNonNegativeInteger;
  4505. cXSUnsignedLong.prototype.builtInKind = cXSConstants.UNSIGNEDLONG_DT;
  4506. cXSUnsignedLong.cast = function(vValue) {
  4507. var oValue;
  4508. try {
  4509. oValue = cXSInteger.cast(vValue);
  4510. }
  4511. catch (oError) {
  4512. throw oError;
  4513. }
  4514. // facet validation
  4515. if (oValue.value >= 1 && oValue.value <= 18446744073709551615)
  4516. return new cXSUnsignedLong(oValue.value);
  4517. //
  4518. throw new cException("FORG0001");
  4519. };
  4520. //
  4521. fStaticContext_defineSystemDataType("unsignedLong", cXSUnsignedLong);
  4522. /*
  4523. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4524. *
  4525. * Copyright (c) 2012 Sergey Ilinsky
  4526. * Dual licensed under the MIT and GPL licenses.
  4527. *
  4528. *
  4529. */
  4530. function cXSUnsignedInt(nValue) {
  4531. this.value = nValue;
  4532. };
  4533. cXSUnsignedInt.prototype = new cXSNonNegativeInteger;
  4534. cXSUnsignedInt.prototype.builtInKind = cXSConstants.UNSIGNEDINT_DT;
  4535. cXSUnsignedInt.cast = function(vValue) {
  4536. var oValue;
  4537. try {
  4538. oValue = cXSInteger.cast(vValue);
  4539. }
  4540. catch (oError) {
  4541. throw oError;
  4542. }
  4543. // facet validation
  4544. if (oValue.value >= 1 && oValue.value <= 4294967295)
  4545. return new cXSUnsignedInt(oValue.value);
  4546. //
  4547. throw new cException("FORG0001");
  4548. };
  4549. //
  4550. fStaticContext_defineSystemDataType("unsignedInt", cXSUnsignedInt);
  4551. /*
  4552. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4553. *
  4554. * Copyright (c) 2012 Sergey Ilinsky
  4555. * Dual licensed under the MIT and GPL licenses.
  4556. *
  4557. *
  4558. */
  4559. function cXSUnsignedShort(nValue) {
  4560. this.value = nValue;
  4561. };
  4562. cXSUnsignedShort.prototype = new cXSUnsignedInt;
  4563. cXSUnsignedShort.prototype.builtInKind = cXSConstants.UNSIGNEDSHORT_DT;
  4564. cXSUnsignedShort.cast = function(vValue) {
  4565. var oValue;
  4566. try {
  4567. oValue = cXSInteger.cast(vValue);
  4568. }
  4569. catch (oError) {
  4570. throw oError;
  4571. }
  4572. // facet validation
  4573. if (oValue.value >= 1 && oValue.value <= 65535)
  4574. return new cXSUnsignedShort(oValue.value);
  4575. //
  4576. throw new cException("FORG0001");
  4577. };
  4578. //
  4579. fStaticContext_defineSystemDataType("unsignedShort", cXSUnsignedShort);
  4580. /*
  4581. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4582. *
  4583. * Copyright (c) 2012 Sergey Ilinsky
  4584. * Dual licensed under the MIT and GPL licenses.
  4585. *
  4586. *
  4587. */
  4588. function cXSUnsignedByte(nValue) {
  4589. this.value = nValue;
  4590. };
  4591. cXSUnsignedByte.prototype = new cXSUnsignedShort;
  4592. cXSUnsignedByte.prototype.builtInKind = cXSConstants.UNSIGNEDBYTE_DT;
  4593. cXSUnsignedByte.cast = function(vValue) {
  4594. var oValue;
  4595. try {
  4596. oValue = cXSInteger.cast(vValue);
  4597. }
  4598. catch (oError) {
  4599. throw oError;
  4600. }
  4601. // facet validation
  4602. if (oValue.value >= 1 && oValue.value <= 255)
  4603. return new cXSUnsignedByte(oValue.value);
  4604. //
  4605. throw new cException("FORG0001");
  4606. };
  4607. //
  4608. fStaticContext_defineSystemDataType("unsignedByte", cXSUnsignedByte);
  4609. /*
  4610. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4611. *
  4612. * Copyright (c) 2012 Sergey Ilinsky
  4613. * Dual licensed under the MIT and GPL licenses.
  4614. *
  4615. *
  4616. */
  4617. function cXSNormalizedString(sValue) {
  4618. this.value = sValue;
  4619. };
  4620. cXSNormalizedString.prototype = new cXSString;
  4621. cXSNormalizedString.prototype.builtInKind = cXSConstants.NORMALIZEDSTRING_DT;
  4622. cXSNormalizedString.cast = function(vValue) {
  4623. return new cXSNormalizedString(cString(vValue));
  4624. };
  4625. //
  4626. fStaticContext_defineSystemDataType("normalizedString", cXSNormalizedString);
  4627. /*
  4628. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4629. *
  4630. * Copyright (c) 2012 Sergey Ilinsky
  4631. * Dual licensed under the MIT and GPL licenses.
  4632. *
  4633. *
  4634. */
  4635. function cXSToken(sValue) {
  4636. this.value = sValue;
  4637. };
  4638. cXSToken.prototype = new cXSNormalizedString;
  4639. cXSToken.prototype.builtInKind = cXSConstants.TOKEN_DT;
  4640. cXSToken.cast = function(vValue) {
  4641. return new cXSToken(cString(vValue));
  4642. };
  4643. //
  4644. fStaticContext_defineSystemDataType("token", cXSToken);
  4645. /*
  4646. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4647. *
  4648. * Copyright (c) 2012 Sergey Ilinsky
  4649. * Dual licensed under the MIT and GPL licenses.
  4650. *
  4651. *
  4652. */
  4653. function cXSName(sValue) {
  4654. this.value = sValue;
  4655. };
  4656. cXSName.prototype = new cXSToken;
  4657. cXSName.prototype.builtInKind = cXSConstants.NAME_DT;
  4658. cXSName.cast = function(vValue) {
  4659. return new cXSName(cString(vValue));
  4660. };
  4661. //
  4662. fStaticContext_defineSystemDataType("Name", cXSName);
  4663. /*
  4664. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4665. *
  4666. * Copyright (c) 2012 Sergey Ilinsky
  4667. * Dual licensed under the MIT and GPL licenses.
  4668. *
  4669. *
  4670. */
  4671. function cXSNCName(sValue) {
  4672. this.value = sValue;
  4673. };
  4674. cXSNCName.prototype = new cXSName;
  4675. cXSNCName.prototype.builtInKind = cXSConstants.NCNAME_DT;
  4676. cXSNCName.cast = function(vValue) {
  4677. return new cXSNCName(cString(vValue));
  4678. };
  4679. //
  4680. fStaticContext_defineSystemDataType("NCName", cXSNCName);
  4681. /*
  4682. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4683. *
  4684. * Copyright (c) 2012 Sergey Ilinsky
  4685. * Dual licensed under the MIT and GPL licenses.
  4686. *
  4687. *
  4688. */
  4689. function cXSENTITY(sValue) {
  4690. this.value = sValue;
  4691. };
  4692. cXSENTITY.prototype = new cXSNCName;
  4693. cXSENTITY.prototype.builtInKind = cXSConstants.ENTITY_DT;
  4694. cXSENTITY.cast = function(vValue) {
  4695. return new cXSENTITY(cString(vValue));
  4696. };
  4697. //
  4698. fStaticContext_defineSystemDataType("ENTITY", cXSENTITY);
  4699. /*
  4700. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4701. *
  4702. * Copyright (c) 2012 Sergey Ilinsky
  4703. * Dual licensed under the MIT and GPL licenses.
  4704. *
  4705. *
  4706. */
  4707. function cXSID(sValue) {
  4708. this.value = sValue;
  4709. };
  4710. cXSID.prototype = new cXSNCName;
  4711. cXSID.prototype.builtInKind = cXSConstants.ID_DT;
  4712. cXSID.cast = function(vValue) {
  4713. return new cXSID(cString(vValue));
  4714. };
  4715. //
  4716. fStaticContext_defineSystemDataType("ID", cXSID);
  4717. /*
  4718. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4719. *
  4720. * Copyright (c) 2012 Sergey Ilinsky
  4721. * Dual licensed under the MIT and GPL licenses.
  4722. *
  4723. *
  4724. */
  4725. function cXSIDREF(sValue) {
  4726. this.value = sValue;
  4727. };
  4728. cXSIDREF.prototype = new cXSNCName;
  4729. cXSIDREF.prototype.builtInKind = cXSConstants.IDREF_DT;
  4730. cXSIDREF.cast = function(vValue) {
  4731. return new cXSIDREF(cString(vValue));
  4732. };
  4733. //
  4734. fStaticContext_defineSystemDataType("IDREF", cXSIDREF);
  4735. /*
  4736. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4737. *
  4738. * Copyright (c) 2012 Sergey Ilinsky
  4739. * Dual licensed under the MIT and GPL licenses.
  4740. *
  4741. *
  4742. */
  4743. function cXSLanguage(sValue) {
  4744. this.value = sValue;
  4745. };
  4746. cXSLanguage.prototype = new cXSToken;
  4747. cXSLanguage.prototype.builtInKind = cXSConstants.LANGUAGE_DT;
  4748. cXSLanguage.cast = function(vValue) {
  4749. return new cXSLanguage(cString(vValue));
  4750. };
  4751. //
  4752. fStaticContext_defineSystemDataType("language", cXSLanguage);
  4753. /*
  4754. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4755. *
  4756. * Copyright (c) 2012 Sergey Ilinsky
  4757. * Dual licensed under the MIT and GPL licenses.
  4758. *
  4759. *
  4760. */
  4761. function cXSNMTOKEN(sValue) {
  4762. this.value = sValue;
  4763. };
  4764. cXSNMTOKEN.prototype = new cXSToken;
  4765. cXSNMTOKEN.prototype.builtInKind = cXSConstants.NMTOKEN_DT;
  4766. cXSNMTOKEN.cast = function(vValue) {
  4767. return new cXSNMTOKEN(cString(vValue));
  4768. };
  4769. //
  4770. fStaticContext_defineSystemDataType("NMTOKEN", cXSNMTOKEN);
  4771. /*
  4772. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4773. *
  4774. * Copyright (c) 2012 Sergey Ilinsky
  4775. * Dual licensed under the MIT and GPL licenses.
  4776. *
  4777. *
  4778. */
  4779. function cXTItem() {
  4780. };
  4781. /*
  4782. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4783. *
  4784. * Copyright (c) 2012 Sergey Ilinsky
  4785. * Dual licensed under the MIT and GPL licenses.
  4786. *
  4787. *
  4788. */
  4789. function cXTNode() {
  4790. };
  4791. cXTNode.prototype = new cXTItem;
  4792. /*
  4793. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4794. *
  4795. * Copyright (c) 2012 Sergey Ilinsky
  4796. * Dual licensed under the MIT and GPL licenses.
  4797. *
  4798. *
  4799. */
  4800. function cXTAttribute() {
  4801. };
  4802. cXTAttribute.prototype = new cXTNode;
  4803. /*
  4804. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4805. *
  4806. * Copyright (c) 2012 Sergey Ilinsky
  4807. * Dual licensed under the MIT and GPL licenses.
  4808. *
  4809. *
  4810. */
  4811. function cXTComment() {
  4812. };
  4813. cXTComment.prototype = new cXTNode;
  4814. /*
  4815. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4816. *
  4817. * Copyright (c) 2012 Sergey Ilinsky
  4818. * Dual licensed under the MIT and GPL licenses.
  4819. *
  4820. *
  4821. */
  4822. function cXTDocument() {
  4823. };
  4824. cXTDocument.prototype = new cXTNode;
  4825. /*
  4826. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4827. *
  4828. * Copyright (c) 2012 Sergey Ilinsky
  4829. * Dual licensed under the MIT and GPL licenses.
  4830. *
  4831. *
  4832. */
  4833. function cXTElement() {
  4834. };
  4835. cXTElement.prototype = new cXTNode;
  4836. /*
  4837. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4838. *
  4839. * Copyright (c) 2012 Sergey Ilinsky
  4840. * Dual licensed under the MIT and GPL licenses.
  4841. *
  4842. *
  4843. */
  4844. function cXTProcessingInstruction() {
  4845. };
  4846. cXTProcessingInstruction.prototype = new cXTNode;
  4847. /*
  4848. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4849. *
  4850. * Copyright (c) 2012 Sergey Ilinsky
  4851. * Dual licensed under the MIT and GPL licenses.
  4852. *
  4853. *
  4854. */
  4855. function cXTText() {
  4856. };
  4857. cXTText.prototype = new cXTNode;
  4858. /*
  4859. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4860. *
  4861. * Copyright (c) 2012 Sergey Ilinsky
  4862. * Dual licensed under the MIT and GPL licenses.
  4863. *
  4864. *
  4865. */
  4866. /*
  4867. 12.1 Comparisons of base64Binary and hexBinary Values
  4868. op:hexBinary-equal
  4869. op:base64Binary-equal
  4870. */
  4871. hStaticContext_operators["hexBinary-equal"] = function(oLeft, oRight) {
  4872. return new cXSBoolean(oLeft.valueOf() == oRight.valueOf());
  4873. };
  4874. hStaticContext_operators["base64Binary-equal"] = function(oLeft, oRight) {
  4875. return new cXSBoolean(oLeft.valueOf() == oRight.valueOf());
  4876. };
  4877. /*
  4878. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4879. *
  4880. * Copyright (c) 2012 Sergey Ilinsky
  4881. * Dual licensed under the MIT and GPL licenses.
  4882. *
  4883. *
  4884. */
  4885. /*
  4886. 9.2 Operators on Boolean Values
  4887. op:boolean-equal
  4888. op:boolean-less-than
  4889. op:boolean-greater-than
  4890. */
  4891. // 9.2 Operators on Boolean Values
  4892. // op:boolean-equal($value1 as xs:boolean, $value2 as xs:boolean) as xs:boolean
  4893. hStaticContext_operators["boolean-equal"] = function(oLeft, oRight) {
  4894. return new cXSBoolean(oLeft.valueOf() == oRight.valueOf());
  4895. };
  4896. // op:boolean-less-than($arg1 as xs:boolean, $arg2 as xs:boolean) as xs:boolean
  4897. hStaticContext_operators["boolean-less-than"] = function(oLeft, oRight) {
  4898. return new cXSBoolean(oLeft.valueOf() < oRight.valueOf());
  4899. };
  4900. // op:boolean-greater-than($arg1 as xs:boolean, $arg2 as xs:boolean) as xs:boolean
  4901. hStaticContext_operators["boolean-greater-than"] = function(oLeft, oRight) {
  4902. return new cXSBoolean(oLeft.valueOf() > oRight.valueOf());
  4903. };
  4904. /*
  4905. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  4906. *
  4907. * Copyright (c) 2012 Sergey Ilinsky
  4908. * Dual licensed under the MIT and GPL licenses.
  4909. *
  4910. *
  4911. */
  4912. /*
  4913. 10.4 Comparison Operators on Duration, Date and Time Values
  4914. op:yearMonthDuration-less-than
  4915. op:yearMonthDuration-greater-than
  4916. op:dayTimeDuration-less-than
  4917. op:dayTimeDuration-greater-than
  4918. op:duration-equal
  4919. op:dateTime-equal
  4920. op:dateTime-less-than
  4921. op:dateTime-greater-than
  4922. op:date-equal
  4923. op:date-less-than
  4924. op:date-greater-than
  4925. op:time-equal
  4926. op:time-less-than
  4927. op:time-greater-than
  4928. op:gYearMonth-equal
  4929. op:gYear-equal
  4930. op:gMonthDay-equal
  4931. op:gMonth-equal
  4932. op:gDay-equal
  4933. 10.6 Arithmetic Operators on Durations
  4934. op:add-yearMonthDurations
  4935. op:subtract-yearMonthDurations
  4936. op:multiply-yearMonthDuration
  4937. op:divide-yearMonthDuration
  4938. op:divide-yearMonthDuration-by-yearMonthDuration
  4939. op:add-dayTimeDurations
  4940. op:subtract-dayTimeDurations
  4941. op:multiply-dayTimeDuration
  4942. op:divide-dayTimeDuration
  4943. op:divide-dayTimeDuration-by-dayTimeDuration
  4944. 10.8 Arithmetic Operators on Durations, Dates and Times
  4945. op:subtract-dateTimes
  4946. op:subtract-dates
  4947. op:subtract-times
  4948. op:add-yearMonthDuration-to-dateTime
  4949. op:add-dayTimeDuration-to-dateTime
  4950. op:subtract-yearMonthDuration-from-dateTime
  4951. op:subtract-dayTimeDuration-from-dateTime
  4952. op:add-yearMonthDuration-to-date
  4953. op:add-dayTimeDuration-to-date
  4954. op:subtract-yearMonthDuration-from-date
  4955. op:subtract-dayTimeDuration-from-date
  4956. op:add-dayTimeDuration-to-time
  4957. op:subtract-dayTimeDuration-from-time
  4958. */
  4959. // 10.4 Comparison Operators on Duration, Date and Time Values
  4960. // op:yearMonthDuration-less-than($arg1 as xs:yearMonthDuration, $arg2 as xs:yearMonthDuration) as xs:boolean
  4961. hStaticContext_operators["yearMonthDuration-less-than"] = function(oLeft, oRight) {
  4962. return new cXSBoolean(fOperator_yearMonthDuration_toMonths(oLeft) < fOperator_yearMonthDuration_toMonths(oRight));
  4963. };
  4964. // op:yearMonthDuration-greater-than($arg1 as xs:yearMonthDuration, $arg2 as xs:yearMonthDuration) as xs:boolean
  4965. hStaticContext_operators["yearMonthDuration-greater-than"] = function(oLeft, oRight) {
  4966. return new cXSBoolean(fOperator_yearMonthDuration_toMonths(oLeft) > fOperator_yearMonthDuration_toMonths(oRight));
  4967. };
  4968. // op:dayTimeDuration-less-than($arg1 as dayTimeDuration, $arg2 as dayTimeDuration) as xs:boolean
  4969. hStaticContext_operators["dayTimeDuration-less-than"] = function(oLeft, oRight) {
  4970. return new cXSBoolean(fOperator_dayTimeDuration_toSeconds(oLeft) < fOperator_dayTimeDuration_toSeconds(oRight));
  4971. };
  4972. // op:dayTimeDuration-greater-than($arg1 as dayTimeDuration, $arg2 as dayTimeDuration) as xs:boolean
  4973. hStaticContext_operators["dayTimeDuration-greater-than"] = function(oLeft, oRight) {
  4974. return new cXSBoolean(fOperator_dayTimeDuration_toSeconds(oLeft) > fOperator_dayTimeDuration_toSeconds(oRight));
  4975. };
  4976. // op:duration-equal($arg1 as xs:duration, $arg2 as xs:duration) as xs:boolean
  4977. hStaticContext_operators["duration-equal"] = function(oLeft, oRight) {
  4978. return new cXSBoolean(oLeft.negative == oRight.negative
  4979. && fOperator_yearMonthDuration_toMonths(oLeft) == fOperator_yearMonthDuration_toMonths(oRight)
  4980. && fOperator_dayTimeDuration_toSeconds(oLeft) == fOperator_dayTimeDuration_toSeconds(oRight));
  4981. };
  4982. // op:dateTime-equal($arg1 as xs:dateTime, $arg2 as xs:dateTime) as xs:boolean
  4983. hStaticContext_operators["dateTime-equal"] = function(oLeft, oRight) {
  4984. return fOperator_compareDateTimes(oLeft, oRight, 'eq');
  4985. };
  4986. // op:dateTime-less-than($arg1 as xs:dateTime, $arg2 as xs:dateTime) as xs:boolean
  4987. hStaticContext_operators["dateTime-less-than"] = function(oLeft, oRight) {
  4988. return fOperator_compareDateTimes(oLeft, oRight, 'lt');
  4989. };
  4990. //op:dateTime-greater-than($arg1 as xs:dateTime, $arg2 as xs:dateTime) as xs:boolean
  4991. hStaticContext_operators["dateTime-greater-than"] = function(oLeft, oRight) {
  4992. return fOperator_compareDateTimes(oLeft, oRight, 'gt');
  4993. };
  4994. // op:date-equal($arg1 as xs:date, $arg2 as xs:date) as xs:boolean
  4995. hStaticContext_operators["date-equal"] = function(oLeft, oRight) {
  4996. return fOperator_compareDates(oLeft, oRight, 'eq');
  4997. };
  4998. // op:date-less-than($arg1 as xs:date, $arg2 as xs:date) as xs:boolean
  4999. hStaticContext_operators["date-less-than"] = function(oLeft, oRight) {
  5000. return fOperator_compareDates(oLeft, oRight, 'lt');
  5001. };
  5002. // op:date-greater-than($arg1 as xs:date, $arg2 as xs:date) as xs:boolean
  5003. hStaticContext_operators["date-greater-than"] = function(oLeft, oRight) {
  5004. return fOperator_compareDates(oLeft, oRight, 'gt');
  5005. };
  5006. // op:time-equal($arg1 as xs:time, $arg2 as xs:time) as xs:boolean
  5007. hStaticContext_operators["time-equal"] = function(oLeft, oRight) {
  5008. return fOperator_compareTimes(oLeft, oRight, 'eq');
  5009. };
  5010. // op:time-less-than($arg1 as xs:time, $arg2 as xs:time) as xs:boolean
  5011. hStaticContext_operators["time-less-than"] = function(oLeft, oRight) {
  5012. return fOperator_compareTimes(oLeft, oRight, 'lt');
  5013. };
  5014. // op:time-greater-than($arg1 as xs:time, $arg2 as xs:time) as xs:boolean
  5015. hStaticContext_operators["time-greater-than"] = function(oLeft, oRight) {
  5016. return fOperator_compareTimes(oLeft, oRight, 'gt');
  5017. };
  5018. // op:gYearMonth-equal($arg1 as xs:gYearMonth, $arg2 as xs:gYearMonth) as xs:boolean
  5019. hStaticContext_operators["gYearMonth-equal"] = function(oLeft, oRight) {
  5020. return fOperator_compareDateTimes(
  5021. new cXSDateTime(oLeft.year, oLeft.month, fXSDate_getDaysForYearMonth(oLeft.year, oLeft.month), 0, 0, 0, oLeft.timezone == null ? this.timezone : oLeft.timezone),
  5022. new cXSDateTime(oRight.year, oRight.month, fXSDate_getDaysForYearMonth(oRight.year, oRight.month), 0, 0, 0, oRight.timezone == null ? this.timezone : oRight.timezone),
  5023. 'eq'
  5024. );
  5025. };
  5026. // op:gYear-equal($arg1 as xs:gYear, $arg2 as xs:gYear) as xs:boolean
  5027. hStaticContext_operators["gYear-equal"] = function(oLeft, oRight) {
  5028. return fOperator_compareDateTimes(
  5029. new cXSDateTime(oLeft.year, 1, 1, 0, 0, 0, oLeft.timezone == null ? this.timezone : oLeft.timezone),
  5030. new cXSDateTime(oRight.year, 1, 1, 0, 0, 0, oRight.timezone == null ? this.timezone : oRight.timezone),
  5031. 'eq'
  5032. );
  5033. };
  5034. // op:gMonthDay-equal($arg1 as xs:gMonthDay, $arg2 as xs:gMonthDay) as xs:boolean
  5035. hStaticContext_operators["gMonthDay-equal"] = function(oLeft, oRight) {
  5036. return fOperator_compareDateTimes(
  5037. new cXSDateTime(1972, oLeft.month, oLeft.day, 0, 0, 0, oLeft.timezone == null ? this.timezone : oLeft.timezone),
  5038. new cXSDateTime(1972, oRight.month, oRight.day, 0, 0, 0, oRight.timezone == null ? this.timezone : oRight.timezone),
  5039. 'eq'
  5040. );
  5041. };
  5042. // op:gMonth-equal($arg1 as xs:gMonth, $arg2 as xs:gMonth) as xs:boolean
  5043. hStaticContext_operators["gMonth-equal"] = function(oLeft, oRight) {
  5044. return fOperator_compareDateTimes(
  5045. new cXSDateTime(1972, oLeft.month, fXSDate_getDaysForYearMonth(1972, oRight.month), 0, 0, 0, oLeft.timezone == null ? this.timezone : oLeft.timezone),
  5046. new cXSDateTime(1972, oRight.month, fXSDate_getDaysForYearMonth(1972, oRight.month), 0, 0, 0, oRight.timezone == null ? this.timezone : oRight.timezone),
  5047. 'eq'
  5048. );
  5049. };
  5050. // op:gDay-equal($arg1 as xs:gDay, $arg2 as xs:gDay) as xs:boolean
  5051. hStaticContext_operators["gDay-equal"] = function(oLeft, oRight) {
  5052. return fOperator_compareDateTimes(
  5053. new cXSDateTime(1972, 12, oLeft.day, 0, 0, 0, oLeft.timezone == null ? this.timezone : oLeft.timezone),
  5054. new cXSDateTime(1972, 12, oRight.day, 0, 0, 0, oRight.timezone == null ? this.timezone : oRight.timezone),
  5055. 'eq'
  5056. );
  5057. };
  5058. // 10.6 Arithmetic Operators on Durations
  5059. // op:add-yearMonthDurations($arg1 as xs:yearMonthDuration, $arg2 as xs:yearMonthDuration) as xs:yearMonthDuration
  5060. hStaticContext_operators["add-yearMonthDurations"] = function(oLeft, oRight) {
  5061. return fOperator_yearMonthDuration_fromMonths(fOperator_yearMonthDuration_toMonths(oLeft) + fOperator_yearMonthDuration_toMonths(oRight));
  5062. };
  5063. // op:subtract-yearMonthDurations($arg1 as xs:yearMonthDuration, $arg2 as xs:yearMonthDuration) as xs:yearMonthDuration
  5064. hStaticContext_operators["subtract-yearMonthDurations"] = function(oLeft, oRight) {
  5065. return fOperator_yearMonthDuration_fromMonths(fOperator_yearMonthDuration_toMonths(oLeft) - fOperator_yearMonthDuration_toMonths(oRight));
  5066. };
  5067. // op:multiply-yearMonthDuration($arg1 as xs:yearMonthDuration, $arg2 as xs:double) as xs:yearMonthDuration
  5068. hStaticContext_operators["multiply-yearMonthDuration"] = function(oLeft, oRight) {
  5069. return fOperator_yearMonthDuration_fromMonths(fOperator_yearMonthDuration_toMonths(oLeft) * oRight);
  5070. };
  5071. // op:divide-yearMonthDuration($arg1 as xs:yearMonthDuration, $arg2 as xs:double) as xs:yearMonthDuration
  5072. hStaticContext_operators["divide-yearMonthDuration"] = function(oLeft, oRight) {
  5073. return fOperator_yearMonthDuration_fromMonths(fOperator_yearMonthDuration_toMonths(oLeft) / oRight);
  5074. };
  5075. // op:divide-yearMonthDuration-by-yearMonthDuration($arg1 as xs:yearMonthDuration, $arg2 as xs:yearMonthDuration) as xs:decimal
  5076. hStaticContext_operators["divide-yearMonthDuration-by-yearMonthDuration"] = function(oLeft, oRight) {
  5077. return new cXSDecimal(fOperator_yearMonthDuration_toMonths(oLeft) / fOperator_yearMonthDuration_toMonths(oRight));
  5078. };
  5079. // op:add-dayTimeDurations($arg1 as xs:dayTimeDuration, $arg2 as xs:dayTimeDuration) as xs:dayTimeDuration
  5080. hStaticContext_operators["add-dayTimeDurations"] = function(oLeft, oRight) {
  5081. return fOperator_dayTimeDuration_fromSeconds(fOperator_dayTimeDuration_toSeconds(oLeft) + fOperator_dayTimeDuration_toSeconds(oRight));
  5082. };
  5083. // op:subtract-dayTimeDurations($arg1 as xs:dayTimeDuration, $arg2 as xs:dayTimeDuration) as xs:dayTimeDuration
  5084. hStaticContext_operators["subtract-dayTimeDurations"] = function(oLeft, oRight) {
  5085. return fOperator_dayTimeDuration_fromSeconds(fOperator_dayTimeDuration_toSeconds(oLeft) - fOperator_dayTimeDuration_toSeconds(oRight));
  5086. };
  5087. // op:multiply-dayTimeDurations($arg1 as xs:dayTimeDuration, $arg2 as xs:double) as xs:dayTimeDuration
  5088. hStaticContext_operators["multiply-dayTimeDuration"] = function(oLeft, oRight) {
  5089. return fOperator_dayTimeDuration_fromSeconds(fOperator_dayTimeDuration_toSeconds(oLeft) * oRight);
  5090. };
  5091. // op:divide-dayTimeDurations($arg1 as xs:dayTimeDuration, $arg2 as xs:double) as xs:dayTimeDuration
  5092. hStaticContext_operators["divide-dayTimeDuration"] = function(oLeft, oRight) {
  5093. return fOperator_dayTimeDuration_fromSeconds(fOperator_dayTimeDuration_toSeconds(oLeft) / oRight);
  5094. };
  5095. // op:divide-dayTimeDuration-by-dayTimeDuration($arg1 as xs:dayTimeDuration, $arg2 as xs:dayTimeDuration) as xs:decimal
  5096. hStaticContext_operators["divide-dayTimeDuration-by-dayTimeDuration"] = function(oLeft, oRight) {
  5097. return new cXSDecimal(fOperator_dayTimeDuration_toSeconds(oLeft) / fOperator_dayTimeDuration_toSeconds(oRight));
  5098. };
  5099. // 10.8 Arithmetic Operators on Durations, Dates and Times
  5100. // op:subtract-dateTimes($arg1 as xs:dateTime, $arg2 as xs:dateTime) as xs:dayTimeDuration
  5101. hStaticContext_operators["subtract-dateTimes"] = function(oLeft, oRight) {
  5102. return fOperator_dayTimeDuration_fromSeconds(fOperator_dateTime_toSeconds(oLeft) - fOperator_dateTime_toSeconds(oRight));
  5103. };
  5104. // op:subtract-dates($arg1 as xs:date, $arg2 as xs:date) as xs:dayTimeDuration
  5105. hStaticContext_operators["subtract-dates"] = function(oLeft, oRight) {
  5106. return fOperator_dayTimeDuration_fromSeconds(fOperator_dateTime_toSeconds(oLeft) - fOperator_dateTime_toSeconds(oRight));
  5107. };
  5108. // op:subtract-times($arg1 as xs:time, $arg2 as xs:time) as xs:dayTimeDuration
  5109. hStaticContext_operators["subtract-times"] = function(oLeft, oRight) {
  5110. return fOperator_dayTimeDuration_fromSeconds(fOperator_time_toSeconds(oLeft) - fOperator_time_toSeconds(oRight));
  5111. };
  5112. // op:add-yearMonthDuration-to-dateTime($arg1 as xs:dateTime, $arg2 as xs:yearMonthDuration) as xs:dateTime
  5113. hStaticContext_operators["add-yearMonthDuration-to-dateTime"] = function(oLeft, oRight) {
  5114. return fOperator_addYearMonthDuration2DateTime(oLeft, oRight, '+');
  5115. };
  5116. // op:add-dayTimeDuration-to-dateTime($arg1 as xs:dateTime, $arg2 as xs:dayTimeDuration) as xs:dateTime
  5117. hStaticContext_operators["add-dayTimeDuration-to-dateTime"] = function(oLeft, oRight) {
  5118. return fOperator_addDayTimeDuration2DateTime(oLeft, oRight, '+');
  5119. };
  5120. // op:subtract-yearMonthDuration-from-dateTime($arg1 as xs:dateTime, $arg2 as xs:yearMonthDuration) as xs:dateTime
  5121. hStaticContext_operators["subtract-yearMonthDuration-from-dateTime"] = function(oLeft, oRight) {
  5122. return fOperator_addYearMonthDuration2DateTime(oLeft, oRight, '-');
  5123. };
  5124. // op:subtract-dayTimeDuration-from-dateTime($arg1 as xs:dateTime, $arg2 as xs:dayTimeDuration) as xs:dateTime
  5125. hStaticContext_operators["subtract-dayTimeDuration-from-dateTime"] = function(oLeft, oRight) {
  5126. return fOperator_addDayTimeDuration2DateTime(oLeft, oRight, '-');
  5127. };
  5128. // op:add-yearMonthDuration-to-date($arg1 as xs:date, $arg2 as xs:yearMonthDuration) as xs:date
  5129. hStaticContext_operators["add-yearMonthDuration-to-date"] = function(oLeft, oRight) {
  5130. return fOperator_addYearMonthDuration2DateTime(oLeft, oRight, '+');
  5131. };
  5132. // op:add-dayTimeDuration-to-date($arg1 as xs:date, $arg2 as xs:dayTimeDuration) as xs:date
  5133. hStaticContext_operators["add-dayTimeDuration-to-date"] = function(oLeft, oRight) {
  5134. return fOperator_addDayTimeDuration2DateTime(oLeft, oRight, '+');
  5135. };
  5136. // op:subtract-yearMonthDuration-from-date($arg1 as xs:date, $arg2 as xs:yearMonthDuration) as xs:date
  5137. hStaticContext_operators["subtract-yearMonthDuration-from-date"] = function(oLeft, oRight) {
  5138. return fOperator_addYearMonthDuration2DateTime(oLeft, oRight, '-');
  5139. };
  5140. // op:subtract-dayTimeDuration-from-date($arg1 as xs:date, $arg2 as xs:dayTimeDuration) as xs:date
  5141. hStaticContext_operators["subtract-dayTimeDuration-from-date"] = function(oLeft, oRight) {
  5142. return fOperator_addDayTimeDuration2DateTime(oLeft, oRight, '-');
  5143. };
  5144. // op:add-dayTimeDuration-to-time($arg1 as xs:time, $arg2 as xs:dayTimeDuration) as xs:time
  5145. hStaticContext_operators["add-dayTimeDuration-to-time"] = function(oLeft, oRight) {
  5146. var oValue = new cXSTime(oLeft.hours, oLeft.minutes, oLeft.seconds, oLeft.timezone);
  5147. oValue.hours += oRight.hours;
  5148. oValue.minutes += oRight.minutes;
  5149. oValue.seconds += oRight.seconds;
  5150. //
  5151. return fXSTime_normalize(oValue);
  5152. };
  5153. // op:subtract-dayTimeDuration-from-time($arg1 as xs:time, $arg2 as xs:dayTimeDuration) as xs:time
  5154. hStaticContext_operators["subtract-dayTimeDuration-from-time"] = function(oLeft, oRight) {
  5155. var oValue = new cXSTime(oLeft.hours, oLeft.minutes, oLeft.seconds, oLeft.timezone);
  5156. oValue.hours -= oRight.hours;
  5157. oValue.minutes -= oRight.minutes;
  5158. oValue.seconds -= oRight.seconds;
  5159. //
  5160. return fXSTime_normalize(oValue);
  5161. };
  5162. function fOperator_compareTimes(oLeft, oRight, sComparator) {
  5163. var nLeft = fOperator_time_toSeconds(oLeft),
  5164. nRight = fOperator_time_toSeconds(oRight);
  5165. return new cXSBoolean(sComparator == 'lt' ? nLeft < nRight : sComparator == 'gt' ? nLeft > nRight : nLeft == nRight);
  5166. };
  5167. function fOperator_compareDates(oLeft, oRight, sComparator) {
  5168. return fOperator_compareDateTimes(cXSDateTime.cast(oLeft), cXSDateTime.cast(oRight), sComparator);
  5169. };
  5170. function fOperator_compareDateTimes(oLeft, oRight, sComparator) {
  5171. // Adjust object time zone to Z and compare as strings
  5172. var oTimezone = new cXSDayTimeDuration(0, 0, 0, 0),
  5173. sLeft = fFunction_dateTime_adjustTimezone(oLeft, oTimezone).toString(),
  5174. sRight = fFunction_dateTime_adjustTimezone(oRight, oTimezone).toString();
  5175. return new cXSBoolean(sComparator == 'lt' ? sLeft < sRight : sComparator == 'gt' ? sLeft > sRight : sLeft == sRight);
  5176. };
  5177. function fOperator_addYearMonthDuration2DateTime(oLeft, oRight, sOperator) {
  5178. var oValue;
  5179. if (oLeft instanceof cXSDate)
  5180. oValue = new cXSDate(oLeft.year, oLeft.month, oLeft.day, oLeft.timezone, oLeft.negative);
  5181. else
  5182. if (oLeft instanceof cXSDateTime)
  5183. oValue = new cXSDateTime(oLeft.year, oLeft.month, oLeft.day, oLeft.hours, oLeft.minutes, oLeft.seconds, oLeft.timezone, oLeft.negative);
  5184. //
  5185. oValue.year = oValue.year + oRight.year * (sOperator == '-' ?-1 : 1);
  5186. oValue.month = oValue.month + oRight.month * (sOperator == '-' ?-1 : 1);
  5187. //
  5188. fXSDate_normalize(oValue, true);
  5189. // Correct day if out of month range
  5190. var nDay = fXSDate_getDaysForYearMonth(oValue.year, oValue.month);
  5191. if (oValue.day > nDay)
  5192. oValue.day = nDay;
  5193. //
  5194. return oValue;
  5195. };
  5196. function fOperator_addDayTimeDuration2DateTime(oLeft, oRight, sOperator) {
  5197. var oValue;
  5198. if (oLeft instanceof cXSDate) {
  5199. var nValue = (oRight.hours * 60 + oRight.minutes) * 60 + oRight.seconds;
  5200. oValue = new cXSDate(oLeft.year, oLeft.month, oLeft.day, oLeft.timezone, oLeft.negative);
  5201. oValue.day = oValue.day + oRight.day * (sOperator == '-' ?-1 : 1) - 1 * (nValue && sOperator == '-');
  5202. //
  5203. fXSDate_normalize(oValue);
  5204. }
  5205. else
  5206. if (oLeft instanceof cXSDateTime) {
  5207. oValue = new cXSDateTime(oLeft.year, oLeft.month, oLeft.day, oLeft.hours, oLeft.minutes, oLeft.seconds, oLeft.timezone, oLeft.negative);
  5208. oValue.seconds = oValue.seconds + oRight.seconds * (sOperator == '-' ?-1 : 1);
  5209. oValue.minutes = oValue.minutes + oRight.minutes * (sOperator == '-' ?-1 : 1);
  5210. oValue.hours = oValue.hours + oRight.hours * (sOperator == '-' ?-1 : 1);
  5211. oValue.day = oValue.day + oRight.day * (sOperator == '-' ?-1 : 1);
  5212. //
  5213. fXSDateTime_normalize(oValue);
  5214. }
  5215. return oValue;
  5216. };
  5217. // xs:dayTimeDuration to/from seconds
  5218. function fOperator_dayTimeDuration_toSeconds(oDuration) {
  5219. return (((oDuration.day * 24 + oDuration.hours) * 60 + oDuration.minutes) * 60 + oDuration.seconds) * (oDuration.negative ? -1 : 1);
  5220. };
  5221. function fOperator_dayTimeDuration_fromSeconds(nValue) {
  5222. var bNegative =(nValue = cMath.round(nValue)) < 0,
  5223. nDays = ~~((nValue = cMath.abs(nValue)) / 86400),
  5224. nHours = ~~((nValue -= nDays * 3600 * 24) / 3600),
  5225. nMinutes= ~~((nValue -= nHours * 3600) / 60),
  5226. nSeconds = nValue -= nMinutes * 60;
  5227. return new cXSDayTimeDuration(nDays, nHours, nMinutes, nSeconds, bNegative);
  5228. };
  5229. // xs:yearMonthDuration to/from months
  5230. function fOperator_yearMonthDuration_toMonths(oDuration) {
  5231. return (oDuration.year * 12 + oDuration.month) * (oDuration.negative ? -1 : 1);
  5232. };
  5233. function fOperator_yearMonthDuration_fromMonths(nValue) {
  5234. var nNegative =(nValue = cMath.round(nValue)) < 0,
  5235. nYears = ~~((nValue = cMath.abs(nValue)) / 12),
  5236. nMonths = nValue -= nYears * 12;
  5237. return new cXSYearMonthDuration(nYears, nMonths, nNegative);
  5238. };
  5239. // xs:time to seconds
  5240. function fOperator_time_toSeconds(oTime) {
  5241. return oTime.seconds + (oTime.minutes - (oTime.timezone != null ? oTime.timezone % 60 : 0) + (oTime.hours - (oTime.timezone != null ? ~~(oTime.timezone / 60) : 0)) * 60) * 60;
  5242. };
  5243. // This function unlike all other date-related functions rely on interpretor's dateTime handling
  5244. function fOperator_dateTime_toSeconds(oValue) {
  5245. var oDate = new cDate((oValue.negative ? -1 : 1) * oValue.year, oValue.month, oValue.day, 0, 0, 0, 0);
  5246. if (oValue instanceof cXSDateTime) {
  5247. oDate.setHours(oValue.hours);
  5248. oDate.setMinutes(oValue.minutes);
  5249. oDate.setSeconds(oValue.seconds);
  5250. }
  5251. if (oValue.timezone != null)
  5252. oDate.setMinutes(oDate.getMinutes() - oValue.timezone);
  5253. return oDate.getTime() / 1000;
  5254. };
  5255. /*
  5256. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  5257. *
  5258. * Copyright (c) 2012 Sergey Ilinsky
  5259. * Dual licensed under the MIT and GPL licenses.
  5260. *
  5261. *
  5262. */
  5263. /*
  5264. 14 Functions and Operators on Nodes
  5265. op:is-same-node
  5266. op:node-before
  5267. op:node-after
  5268. */
  5269. // 14 Operators on Nodes
  5270. // op:is-same-node($parameter1 as node(), $parameter2 as node()) as xs:boolean
  5271. hStaticContext_operators["is-same-node"] = function(oLeft, oRight) {
  5272. return new cXSBoolean(this.DOMAdapter.isSameNode(oLeft, oRight));
  5273. };
  5274. // op:node-before($parameter1 as node(), $parameter2 as node()) as xs:boolean
  5275. hStaticContext_operators["node-before"] = function(oLeft, oRight) {
  5276. return new cXSBoolean(!!(this.DOMAdapter.compareDocumentPosition(oLeft, oRight) & 4));
  5277. };
  5278. // op:node-after($parameter1 as node(), $parameter2 as node()) as xs:boolean
  5279. hStaticContext_operators["node-after"] = function(oLeft, oRight) {
  5280. return new cXSBoolean(!!(this.DOMAdapter.compareDocumentPosition(oLeft, oRight) & 2));
  5281. };
  5282. /*
  5283. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  5284. *
  5285. * Copyright (c) 2012 Sergey Ilinsky
  5286. * Dual licensed under the MIT and GPL licenses.
  5287. *
  5288. *
  5289. */
  5290. /*
  5291. 13.1 Operators on NOTATION
  5292. op:NOTATION-equal
  5293. */
  5294. /*
  5295. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  5296. *
  5297. * Copyright (c) 2012 Sergey Ilinsky
  5298. * Dual licensed under the MIT and GPL licenses.
  5299. *
  5300. *
  5301. */
  5302. /*
  5303. 6.2 Operators on Numeric Values
  5304. op:numeric-add
  5305. op:numeric-subtract
  5306. op:numeric-multiply
  5307. op:numeric-divide
  5308. op:numeric-integer-divide
  5309. op:numeric-mod
  5310. op:numeric-unary-plus
  5311. op:numeric-unary-minus
  5312. 6.3 Comparison Operators on Numeric Values
  5313. op:numeric-equal
  5314. op:numeric-less-than
  5315. op:numeric-greater-than
  5316. */
  5317. // 6.2 Operators on Numeric Values
  5318. function fFunctionCall_numeric_getPower(oLeft, oRight) {
  5319. if (fIsNaN(oLeft) || (cMath.abs(oLeft) == nInfinity) || fIsNaN(oRight) || (cMath.abs(oRight) == nInfinity))
  5320. return 0;
  5321. var aLeft = cString(oLeft).match(rNumericLiteral),
  5322. aRight = cString(oRight).match(rNumericLiteral),
  5323. nPower = cMath.max(1, (aLeft[2] || aLeft[3] || '').length + (aLeft[5] || 0) * (aLeft[4] == '+' ?-1 : 1), (aRight[2] || aRight[3] || '').length + (aRight[5] || 0) * (aRight[4] == '+' ?-1 : 1));
  5324. return nPower + (nPower % 2 ? 0 : 1);
  5325. };
  5326. // op:numeric-add($arg1 as numeric, $arg2 as numeric) as numeric
  5327. hStaticContext_operators["numeric-add"] = function(oLeft, oRight) {
  5328. var nLeft = oLeft.valueOf(),
  5329. nRight = oRight.valueOf(),
  5330. nPower = cMath.pow(10, fFunctionCall_numeric_getPower(nLeft, nRight));
  5331. return fOperator_numeric_getResultOfType(oLeft, oRight, ((nLeft * nPower) + (nRight * nPower))/nPower);
  5332. };
  5333. // op:numeric-subtract($arg1 as numeric, $arg2 as numeric) as numeric
  5334. hStaticContext_operators["numeric-subtract"] = function(oLeft, oRight) {
  5335. var nLeft = oLeft.valueOf(),
  5336. nRight = oRight.valueOf(),
  5337. nPower = cMath.pow(10, fFunctionCall_numeric_getPower(nLeft, nRight));
  5338. return fOperator_numeric_getResultOfType(oLeft, oRight, ((nLeft * nPower) - (nRight * nPower))/nPower);
  5339. };
  5340. // op:numeric-multiply($arg1 as numeric, $arg2 as numeric) as numeric
  5341. hStaticContext_operators["numeric-multiply"] = function(oLeft, oRight) {
  5342. var nLeft = oLeft.valueOf(),
  5343. nRight = oRight.valueOf(),
  5344. nPower = cMath.pow(10, fFunctionCall_numeric_getPower(nLeft, nRight));
  5345. return fOperator_numeric_getResultOfType(oLeft, oRight, ((nLeft * nPower) * (nRight * nPower))/(nPower * nPower));
  5346. };
  5347. // op:numeric-divide($arg1 as numeric, $arg2 as numeric) as numeric
  5348. hStaticContext_operators["numeric-divide"] = function(oLeft, oRight) {
  5349. var nLeft = oLeft.valueOf(),
  5350. nRight = oRight.valueOf(),
  5351. nPower = cMath.pow(10, fFunctionCall_numeric_getPower(nLeft, nRight));
  5352. return fOperator_numeric_getResultOfType(oLeft, oRight, (oLeft * nPower) / (oRight * nPower));
  5353. };
  5354. // op:numeric-integer-divide($arg1 as numeric, $arg2 as numeric) as xs:integer
  5355. hStaticContext_operators["numeric-integer-divide"] = function(oLeft, oRight) {
  5356. var oValue = oLeft / oRight;
  5357. return new cXSInteger(cMath.floor(oValue) + (oValue < 0));
  5358. };
  5359. // op:numeric-mod($arg1 as numeric, $arg2 as numeric) as numeric
  5360. hStaticContext_operators["numeric-mod"] = function(oLeft, oRight) {
  5361. var nLeft = oLeft.valueOf(),
  5362. nRight = oRight.valueOf(),
  5363. nPower = cMath.pow(10, fFunctionCall_numeric_getPower(nLeft, nRight));
  5364. return fOperator_numeric_getResultOfType(oLeft, oRight, ((nLeft * nPower) % (nRight * nPower)) / nPower);
  5365. };
  5366. // op:numeric-unary-plus($arg as numeric) as numeric
  5367. hStaticContext_operators["numeric-unary-plus"] = function(oRight) {
  5368. return oRight;
  5369. };
  5370. // op:numeric-unary-minus($arg as numeric) as numeric
  5371. hStaticContext_operators["numeric-unary-minus"] = function(oRight) {
  5372. oRight.value *=-1;
  5373. return oRight;
  5374. };
  5375. // 6.3 Comparison Operators on Numeric Values
  5376. // op:numeric-equal($arg1 as numeric, $arg2 as numeric) as xs:boolean
  5377. hStaticContext_operators["numeric-equal"] = function(oLeft, oRight) {
  5378. return new cXSBoolean(oLeft.valueOf() == oRight.valueOf());
  5379. };
  5380. // op:numeric-less-than($arg1 as numeric, $arg2 as numeric) as xs:boolean
  5381. hStaticContext_operators["numeric-less-than"] = function(oLeft, oRight) {
  5382. return new cXSBoolean(oLeft.valueOf() < oRight.valueOf());
  5383. };
  5384. // op:numeric-greater-than($arg1 as numeric, $arg2 as numeric) as xs:boolean
  5385. hStaticContext_operators["numeric-greater-than"] = function(oLeft, oRight) {
  5386. return new cXSBoolean(oLeft.valueOf() > oRight.valueOf());
  5387. };
  5388. function fOperator_numeric_getResultOfType(oLeft, oRight, nResult) {
  5389. return new (oLeft instanceof cXSInteger && oRight instanceof cXSInteger && nResult == cMath.round(nResult) ? cXSInteger : cXSDecimal)(nResult);
  5390. };
  5391. /*
  5392. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  5393. *
  5394. * Copyright (c) 2012 Sergey Ilinsky
  5395. * Dual licensed under the MIT and GPL licenses.
  5396. *
  5397. *
  5398. */
  5399. /*
  5400. 11.2 Functions and Operators Related to QNames
  5401. op:QName-equal
  5402. */
  5403. // 11.2 Operators Related to QNames
  5404. // op:QName-equal($arg1 as xs:QName, $arg2 as xs:QName) as xs:boolean
  5405. hStaticContext_operators["QName-equal"] = function(oLeft, oRight) {
  5406. return new cXSBoolean(oLeft.localName == oRight.localName && oLeft.namespaceURI == oRight.namespaceURI);
  5407. };
  5408. /*
  5409. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  5410. *
  5411. * Copyright (c) 2012 Sergey Ilinsky
  5412. * Dual licensed under the MIT and GPL licenses.
  5413. *
  5414. *
  5415. */
  5416. /*
  5417. 15.1 General Functions and Operators on Sequences
  5418. op:concatenate
  5419. 15.3 Equals, Union, Intersection and Except
  5420. op:union
  5421. op:intersect
  5422. op:except
  5423. 15.5 Functions and Operators that Generate Sequences
  5424. op:to
  5425. */
  5426. // 15.1 General Functions and Operators on Sequences
  5427. // op:concatenate($seq1 as item()*, $seq2 as item()*) as item()*
  5428. hStaticContext_operators["concatenate"] = function(oSequence1, oSequence2) {
  5429. return oSequence1.concat(oSequence2);
  5430. };
  5431. // 15.3 Equals, Union, Intersection and Except
  5432. // op:union($parameter1 as node()*, $parameter2 as node()*) as node()*
  5433. hStaticContext_operators["union"] = function(oSequence1, oSequence2) {
  5434. var oSequence = [];
  5435. // Process first collection
  5436. for (var nIndex = 0, nLength = oSequence1.length, oItem; nIndex < nLength; nIndex++) {
  5437. if (!this.DOMAdapter.isNode(oItem = oSequence1[nIndex]))
  5438. throw new cException("XPTY0004"
  5439. ); // Required item type of second operand of 'intersect' is node(); supplied value has item type xs:integer
  5440. //
  5441. if (fArray_indexOf(oSequence, oItem) ==-1)
  5442. oSequence.push(oItem);
  5443. }
  5444. // Process second collection
  5445. for (var nIndex = 0, nLength = oSequence2.length, oItem; nIndex < nLength; nIndex++) {
  5446. if (!this.DOMAdapter.isNode(oItem = oSequence2[nIndex]))
  5447. throw new cException("XPTY0004"
  5448. ); // Required item type of second operand of 'intersect' is node(); supplied value has item type xs:integer
  5449. //
  5450. if (fArray_indexOf(oSequence, oItem) ==-1)
  5451. oSequence.push(oItem);
  5452. }
  5453. return fFunction_sequence_order(oSequence, this);
  5454. };
  5455. // op:intersect($parameter1 as node()*, $parameter2 as node()*) as node()*
  5456. hStaticContext_operators["intersect"] = function(oSequence1, oSequence2) {
  5457. var oSequence = [];
  5458. for (var nIndex = 0, nLength = oSequence1.length, oItem, bFound; nIndex < nLength; nIndex++) {
  5459. if (!this.DOMAdapter.isNode(oItem = oSequence1[nIndex]))
  5460. throw new cException("XPTY0004"
  5461. ); // Required item type of second operand of 'intersect' is node(); supplied value has item type xs:integer
  5462. //
  5463. bFound = false;
  5464. for (var nRightIndex = 0, nRightLength = oSequence2.length;(nRightIndex < nRightLength) && !bFound; nRightIndex++) {
  5465. if (!this.DOMAdapter.isNode(oSequence2[nRightIndex]))
  5466. throw new cException("XPTY0004"
  5467. );
  5468. bFound = this.DOMAdapter.isSameNode(oSequence2[nRightIndex], oItem);
  5469. }
  5470. //
  5471. if (bFound && fArray_indexOf(oSequence, oItem) ==-1)
  5472. oSequence.push(oItem);
  5473. }
  5474. return fFunction_sequence_order(oSequence, this);
  5475. };
  5476. // op:except($parameter1 as node()*, $parameter2 as node()*) as node()*
  5477. hStaticContext_operators["except"] = function(oSequence1, oSequence2) {
  5478. var oSequence = [];
  5479. for (var nIndex = 0, nLength = oSequence1.length, oItem, bFound; nIndex < nLength; nIndex++) {
  5480. if (!this.DOMAdapter.isNode(oItem = oSequence1[nIndex]))
  5481. throw new cException("XPTY0004"
  5482. ); // Required item type of second operand of 'intersect' is node(); supplied value has item type xs:integer
  5483. //
  5484. bFound = false;
  5485. for (var nRightIndex = 0, nRightLength = oSequence2.length;(nRightIndex < nRightLength) && !bFound; nRightIndex++) {
  5486. if (!this.DOMAdapter.isNode(oSequence2[nRightIndex]))
  5487. throw new cException("XPTY0004"
  5488. );
  5489. bFound = this.DOMAdapter.isSameNode(oSequence2[nRightIndex], oItem);
  5490. }
  5491. //
  5492. if (!bFound && fArray_indexOf(oSequence, oItem) ==-1)
  5493. oSequence.push(oItem);
  5494. }
  5495. return fFunction_sequence_order(oSequence, this);
  5496. };
  5497. // 15.5 Functions and Operators that Generate Sequences
  5498. // op:to($firstval as xs:integer, $lastval as xs:integer) as xs:integer*
  5499. hStaticContext_operators["to"] = function(oLeft, oRight) {
  5500. var oSequence = [];
  5501. for (var nIndex = oLeft.valueOf(), nLength = oRight.valueOf(); nIndex <= nLength; nIndex++)
  5502. oSequence.push(new cXSInteger(nIndex));
  5503. //
  5504. return oSequence;
  5505. };
  5506. /*
  5507. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  5508. *
  5509. * Copyright (c) 2012 Sergey Ilinsky
  5510. * Dual licensed under the MIT and GPL licenses.
  5511. *
  5512. *
  5513. */
  5514. /*
  5515. 2 Accessors
  5516. node-name
  5517. nilled
  5518. string
  5519. data
  5520. base-uri
  5521. document-uri
  5522. */
  5523. // fn:node-name($arg as node()?) as xs:QName?
  5524. fStaticContext_defineSystemFunction("node-name", [[cXTNode, '?']], function(oNode) {
  5525. if (oNode != null) {
  5526. var fGetProperty = this.DOMAdapter.getProperty;
  5527. switch (fGetProperty(oNode, "nodeType")) {
  5528. case 1: // ELEMENT_NAME
  5529. case 2: // ATTRIBUTE_NODE
  5530. return new cXSQName(fGetProperty(oNode, "prefix"), fGetProperty(oNode, "localName"), fGetProperty(oNode, "namespaceURI"));
  5531. case 5: // ENTITY_REFERENCE_NODE
  5532. throw "Not implemented";
  5533. case 6: // ENTITY_NODE
  5534. throw "Not implemented";
  5535. case 7: // PROCESSING_INSTRUCTION_NODE
  5536. return new cXSQName(null, fGetProperty(oNode, "target"), null);
  5537. case 10: // DOCUMENT_TYPE_NODE
  5538. return new cXSQName(null, fGetProperty(oNode, "name"), null);
  5539. }
  5540. }
  5541. //
  5542. return null;
  5543. });
  5544. // fn:nilled($arg as node()?) as xs:boolean?
  5545. fStaticContext_defineSystemFunction("nilled", [[cXTNode, '?']], function(oNode) {
  5546. if (oNode != null) {
  5547. if (this.DOMAdapter.getProperty(oNode, "nodeType") == 1)
  5548. return new cXSBoolean(false); // TODO: Determine if node is nilled
  5549. }
  5550. //
  5551. return null;
  5552. });
  5553. // fn:string() as xs:string
  5554. // fn:string($arg as item()?) as xs:string
  5555. fStaticContext_defineSystemFunction("string", [[cXTItem, '?', true]], function(/*[*/oItem/*]*/) {
  5556. if (!arguments.length) {
  5557. if (!this.item)
  5558. throw new cException("XPDY0002");
  5559. oItem = this.item;
  5560. }
  5561. return oItem == null ? new cXSString('') : cXSString.cast(fFunction_sequence_atomize([oItem], this)[0]);
  5562. });
  5563. // fn:data($arg as item()*) as xs:anyAtomicType*
  5564. fStaticContext_defineSystemFunction("data", [[cXTItem, '*']], function(oSequence1) {
  5565. return fFunction_sequence_atomize(oSequence1, this);
  5566. });
  5567. // fn:base-uri() as xs:anyURI?
  5568. // fn:base-uri($arg as node()?) as xs:anyURI?
  5569. fStaticContext_defineSystemFunction("base-uri", [[cXTNode, '?', true]], function(oNode) {
  5570. if (!arguments.length) {
  5571. if (!this.DOMAdapter.isNode(this.item))
  5572. throw new cException("XPTY0004"
  5573. );
  5574. oNode = this.item;
  5575. }
  5576. //
  5577. return cXSAnyURI.cast(new cXSString(this.DOMAdapter.getProperty(oNode, "baseURI") || ''));
  5578. });
  5579. // fn:document-uri($arg as node()?) as xs:anyURI?
  5580. fStaticContext_defineSystemFunction("document-uri", [[cXTNode, '?']], function(oNode) {
  5581. if (oNode != null) {
  5582. var fGetProperty = this.DOMAdapter.getProperty;
  5583. if (fGetProperty(oNode, "nodeType") == 9)
  5584. return cXSAnyURI.cast(new cXSString(fGetProperty(oNode, "documentURI") || ''));
  5585. }
  5586. //
  5587. return null;
  5588. });
  5589. /*
  5590. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  5591. *
  5592. * Copyright (c) 2012 Sergey Ilinsky
  5593. * Dual licensed under the MIT and GPL licenses.
  5594. *
  5595. *
  5596. */
  5597. /*
  5598. 8 Functions on anyURI
  5599. resolve-uri
  5600. */
  5601. // fn:resolve-uri($relative as xs:string?) as xs:anyURI?
  5602. // fn:resolve-uri($relative as xs:string?, $base as xs:string) as xs:anyURI?
  5603. fStaticContext_defineSystemFunction("resolve-uri", [[cXSString, '?'], [cXSString, '', true]], function(sUri, sBaseUri) {
  5604. if (arguments.length < 2) {
  5605. if (!this.DOMAdapter.isNode(this.item))
  5606. throw new cException("XPTY0004"
  5607. );
  5608. sBaseUri = new cXSString(this.DOMAdapter.getProperty(this.item, "baseURI") || '');
  5609. }
  5610. if (sUri == null)
  5611. return null;
  5612. //
  5613. if (sUri.valueOf() == '' || sUri.valueOf().charAt(0) == '#')
  5614. return cXSAnyURI.cast(sBaseUri);
  5615. var oUri = cXSAnyURI.cast(sUri);
  5616. if (oUri.scheme)
  5617. return oUri;
  5618. var oBaseUri = cXSAnyURI.cast(sBaseUri);
  5619. oUri.scheme = oBaseUri.scheme;
  5620. if (!oUri.authority) {
  5621. // authority
  5622. oUri.authority = oBaseUri.authority;
  5623. // path
  5624. if (oUri.path.charAt(0) != '/') {
  5625. var aUriSegments = oUri.path.split('/'),
  5626. aBaseUriSegments = oBaseUri.path.split('/');
  5627. aBaseUriSegments.pop();
  5628. var nBaseUriStart = aBaseUriSegments[0] == '' ? 1 : 0;
  5629. for (var nIndex = 0, nLength = aUriSegments.length; nIndex < nLength; nIndex++) {
  5630. if (aUriSegments[nIndex] == '..') {
  5631. if (aBaseUriSegments.length > nBaseUriStart)
  5632. aBaseUriSegments.pop();
  5633. else {
  5634. aBaseUriSegments.push(aUriSegments[nIndex]);
  5635. nBaseUriStart++;
  5636. }
  5637. }
  5638. else
  5639. if (aUriSegments[nIndex] != '.')
  5640. aBaseUriSegments.push(aUriSegments[nIndex]);
  5641. }
  5642. if (aUriSegments[--nIndex] == '..' || aUriSegments[nIndex] == '.')
  5643. aBaseUriSegments.push('');
  5644. //
  5645. oUri.path = aBaseUriSegments.join('/');
  5646. }
  5647. }
  5648. return oUri;
  5649. });
  5650. /*
  5651. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  5652. *
  5653. * Copyright (c) 2012 Sergey Ilinsky
  5654. * Dual licensed under the MIT and GPL licenses.
  5655. *
  5656. *
  5657. */
  5658. /*
  5659. 9.1 Additional Boolean Constructor Functions
  5660. true
  5661. false
  5662. 9.3 Functions on Boolean Values
  5663. not
  5664. */
  5665. // 9.1 Additional Boolean Constructor Functions
  5666. // fn:true() as xs:boolean
  5667. fStaticContext_defineSystemFunction("true", [], function() {
  5668. return new cXSBoolean(true);
  5669. });
  5670. // fn:false() as xs:boolean
  5671. fStaticContext_defineSystemFunction("false", [], function() {
  5672. return new cXSBoolean(false);
  5673. });
  5674. // 9.3 Functions on Boolean Values
  5675. // fn:not($arg as item()*) as xs:boolean
  5676. fStaticContext_defineSystemFunction("not", [[cXTItem, '*']], function(oSequence1) {
  5677. return new cXSBoolean(!fFunction_sequence_toEBV(oSequence1, this));
  5678. });
  5679. /*
  5680. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  5681. *
  5682. * Copyright (c) 2012 Sergey Ilinsky
  5683. * Dual licensed under the MIT and GPL licenses.
  5684. *
  5685. *
  5686. */
  5687. /*
  5688. 16 Context Functions
  5689. position
  5690. last
  5691. current-dateTime
  5692. current-date
  5693. current-time
  5694. implicit-timezone
  5695. default-collation
  5696. static-base-uri
  5697. */
  5698. // fn:position() as xs:integer
  5699. fStaticContext_defineSystemFunction("position", [], function() {
  5700. return new cXSInteger(this.position);
  5701. });
  5702. // fn:last() as xs:integer
  5703. fStaticContext_defineSystemFunction("last", [], function() {
  5704. return new cXSInteger(this.size);
  5705. });
  5706. // fn:current-dateTime() as xs:dateTime (2004-05-12T18:17:15.125Z)
  5707. fStaticContext_defineSystemFunction("current-dateTime", [], function() {
  5708. return this.dateTime;
  5709. });
  5710. // fn:current-date() as xs:date (2004-05-12+01:00)
  5711. fStaticContext_defineSystemFunction("current-date", [], function() {
  5712. return cXSDate.cast(this.dateTime);
  5713. });
  5714. // fn:current-time() as xs:time (23:17:00.000-05:00)
  5715. fStaticContext_defineSystemFunction("current-time", [], function() {
  5716. return cXSTime.cast(this.dateTime);
  5717. });
  5718. // fn:implicit-timezone() as xs:dayTimeDuration
  5719. fStaticContext_defineSystemFunction("implicit-timezone", [], function() {
  5720. return this.timezone;
  5721. });
  5722. // fn:default-collation() as xs:string
  5723. fStaticContext_defineSystemFunction("default-collation", [], function() {
  5724. return new cXSString(this.staticContext.defaultCollationName);
  5725. });
  5726. // fn:static-base-uri() as xs:anyURI?
  5727. fStaticContext_defineSystemFunction("static-base-uri", [], function() {
  5728. return cXSAnyURI.cast(new cXSString(this.staticContext.baseURI || ''));
  5729. });
  5730. /*
  5731. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  5732. *
  5733. * Copyright (c) 2012 Sergey Ilinsky
  5734. * Dual licensed under the MIT and GPL licenses.
  5735. *
  5736. *
  5737. */
  5738. /*
  5739. 10.5 Component Extraction Functions on Durations, Dates and Times
  5740. years-from-duration
  5741. months-from-duration
  5742. days-from-duration
  5743. hours-from-duration
  5744. minutes-from-duration
  5745. seconds-from-duration
  5746. year-from-dateTime
  5747. month-from-dateTime
  5748. day-from-dateTime
  5749. hours-from-dateTime
  5750. minutes-from-dateTime
  5751. seconds-from-dateTime
  5752. timezone-from-dateTime
  5753. year-from-date
  5754. month-from-date
  5755. day-from-date
  5756. timezone-from-date
  5757. hours-from-time
  5758. minutes-from-time
  5759. seconds-from-time
  5760. timezone-from-time
  5761. 10.7 Timezone Adjustment Functions on Dates and Time Values
  5762. adjust-dateTime-to-timezone
  5763. adjust-date-to-timezone
  5764. adjust-time-to-timezone
  5765. */
  5766. // 10.5 Component Extraction Functions on Durations, Dates and Times
  5767. // functions on duration
  5768. // fn:years-from-duration($arg as xs:duration?) as xs:integer?
  5769. fStaticContext_defineSystemFunction("years-from-duration", [[cXSDuration, '?']], function(oDuration) {
  5770. return fFunction_duration_getComponent(oDuration, "year");
  5771. });
  5772. // fn:months-from-duration($arg as xs:duration?) as xs:integer?
  5773. fStaticContext_defineSystemFunction("months-from-duration", [[cXSDuration, '?']], function(oDuration) {
  5774. return fFunction_duration_getComponent(oDuration, "month");
  5775. });
  5776. // fn:days-from-duration($arg as xs:duration?) as xs:integer?
  5777. fStaticContext_defineSystemFunction("days-from-duration", [[cXSDuration, '?']], function(oDuration) {
  5778. return fFunction_duration_getComponent(oDuration, "day");
  5779. });
  5780. // fn:hours-from-duration($arg as xs:duration?) as xs:integer?
  5781. fStaticContext_defineSystemFunction("hours-from-duration", [[cXSDuration, '?']], function(oDuration) {
  5782. return fFunction_duration_getComponent(oDuration, "hours");
  5783. });
  5784. // fn:minutes-from-duration($arg as xs:duration?) as xs:integer?
  5785. fStaticContext_defineSystemFunction("minutes-from-duration", [[cXSDuration, '?']], function(oDuration) {
  5786. return fFunction_duration_getComponent(oDuration, "minutes");
  5787. });
  5788. // fn:seconds-from-duration($arg as xs:duration?) as xs:decimal?
  5789. fStaticContext_defineSystemFunction("seconds-from-duration", [[cXSDuration, '?']], function(oDuration) {
  5790. return fFunction_duration_getComponent(oDuration, "seconds");
  5791. });
  5792. // functions on dateTime
  5793. // fn:year-from-dateTime($arg as xs:dateTime?) as xs:integer?
  5794. fStaticContext_defineSystemFunction("year-from-dateTime", [[cXSDateTime, '?']], function(oDateTime) {
  5795. return fFunction_dateTime_getComponent(oDateTime, "year");
  5796. });
  5797. // fn:month-from-dateTime($arg as xs:dateTime?) as xs:integer?
  5798. fStaticContext_defineSystemFunction("month-from-dateTime", [[cXSDateTime, '?']], function(oDateTime) {
  5799. return fFunction_dateTime_getComponent(oDateTime, "month");
  5800. });
  5801. // fn:day-from-dateTime($arg as xs:dateTime?) as xs:integer?
  5802. fStaticContext_defineSystemFunction("day-from-dateTime", [[cXSDateTime, '?']], function(oDateTime) {
  5803. return fFunction_dateTime_getComponent(oDateTime, "day");
  5804. });
  5805. // fn:hours-from-dateTime($arg as xs:dateTime?) as xs:integer?
  5806. fStaticContext_defineSystemFunction("hours-from-dateTime", [[cXSDateTime, '?']], function(oDateTime) {
  5807. return fFunction_dateTime_getComponent(oDateTime, "hours");
  5808. });
  5809. // fn:minutes-from-dateTime($arg as xs:dateTime?) as xs:integer?
  5810. fStaticContext_defineSystemFunction("minutes-from-dateTime", [[cXSDateTime, '?']], function(oDateTime) {
  5811. return fFunction_dateTime_getComponent(oDateTime, "minutes");
  5812. });
  5813. // fn:seconds-from-dateTime($arg as xs:dateTime?) as xs:decimal?
  5814. fStaticContext_defineSystemFunction("seconds-from-dateTime", [[cXSDateTime, '?']], function(oDateTime) {
  5815. return fFunction_dateTime_getComponent(oDateTime, "seconds");
  5816. });
  5817. // fn:timezone-from-dateTime($arg as xs:dateTime?) as xs:dayTimeDuration?
  5818. fStaticContext_defineSystemFunction("timezone-from-dateTime", [[cXSDateTime, '?']], function(oDateTime) {
  5819. return fFunction_dateTime_getComponent(oDateTime, "timezone");
  5820. });
  5821. // functions on date
  5822. // fn:year-from-date($arg as xs:date?) as xs:integer?
  5823. fStaticContext_defineSystemFunction("year-from-date", [[cXSDate, '?']], function(oDate) {
  5824. return fFunction_dateTime_getComponent(oDate, "year");
  5825. });
  5826. // fn:month-from-date($arg as xs:date?) as xs:integer?
  5827. fStaticContext_defineSystemFunction("month-from-date", [[cXSDate, '?']], function(oDate) {
  5828. return fFunction_dateTime_getComponent(oDate, "month");
  5829. });
  5830. // fn:day-from-date($arg as xs:date?) as xs:integer?
  5831. fStaticContext_defineSystemFunction("day-from-date", [[cXSDate, '?']], function(oDate) {
  5832. return fFunction_dateTime_getComponent(oDate, "day");
  5833. });
  5834. // fn:timezone-from-date($arg as xs:date?) as xs:dayTimeDuration?
  5835. fStaticContext_defineSystemFunction("timezone-from-date", [[cXSDate, '?']], function(oDate) {
  5836. return fFunction_dateTime_getComponent(oDate, "timezone");
  5837. });
  5838. // functions on time
  5839. // fn:hours-from-time($arg as xs:time?) as xs:integer?
  5840. fStaticContext_defineSystemFunction("hours-from-time", [[cXSTime, '?']], function(oTime) {
  5841. return fFunction_dateTime_getComponent(oTime, "hours");
  5842. });
  5843. // fn:minutes-from-time($arg as xs:time?) as xs:integer?
  5844. fStaticContext_defineSystemFunction("minutes-from-time", [[cXSTime, '?']], function(oTime) {
  5845. return fFunction_dateTime_getComponent(oTime, "minutes");
  5846. });
  5847. // fn:seconds-from-time($arg as xs:time?) as xs:decimal?
  5848. fStaticContext_defineSystemFunction("seconds-from-time", [[cXSTime, '?']], function(oTime) {
  5849. return fFunction_dateTime_getComponent(oTime, "seconds");
  5850. });
  5851. // fn:timezone-from-time($arg as xs:time?) as xs:dayTimeDuration?
  5852. fStaticContext_defineSystemFunction("timezone-from-time", [[cXSTime, '?']], function(oTime) {
  5853. return fFunction_dateTime_getComponent(oTime, "timezone");
  5854. });
  5855. // 10.7 Timezone Adjustment Functions on Dates and Time Values
  5856. // fn:adjust-dateTime-to-timezone($arg as xs:dateTime?) as xs:dateTime?
  5857. // fn:adjust-dateTime-to-timezone($arg as xs:dateTime?, $timezone as xs:dayTimeDuration?) as xs:dateTime?
  5858. fStaticContext_defineSystemFunction("adjust-dateTime-to-timezone", [[cXSDateTime, '?'], [cXSDayTimeDuration, '?', true]], function(oDateTime, oDayTimeDuration) {
  5859. return fFunction_dateTime_adjustTimezone(oDateTime, arguments.length > 1 && oDayTimeDuration != null ? arguments.length > 1 ? oDayTimeDuration : this.timezone : null);
  5860. });
  5861. // fn:adjust-date-to-timezone($arg as xs:date?) as xs:date?
  5862. // fn:adjust-date-to-timezone($arg as xs:date?, $timezone as xs:dayTimeDuration?) as xs:date?
  5863. fStaticContext_defineSystemFunction("adjust-date-to-timezone", [[cXSDate, '?'], [cXSDayTimeDuration, '?', true]], function(oDate, oDayTimeDuration) {
  5864. return fFunction_dateTime_adjustTimezone(oDate, arguments.length > 1 && oDayTimeDuration != null ? arguments.length > 1 ? oDayTimeDuration : this.timezone : null);
  5865. });
  5866. // fn:adjust-time-to-timezone($arg as xs:time?) as xs:time?
  5867. // fn:adjust-time-to-timezone($arg as xs:time?, $timezone as xs:dayTimeDuration?) as xs:time?
  5868. fStaticContext_defineSystemFunction("adjust-time-to-timezone", [[cXSTime, '?'], [cXSDayTimeDuration, '?', true]], function(oTime, oDayTimeDuration) {
  5869. return fFunction_dateTime_adjustTimezone(oTime, arguments.length > 1 && oDayTimeDuration != null ? arguments.length > 1 ? oDayTimeDuration : this.timezone : null);
  5870. });
  5871. //
  5872. function fFunction_duration_getComponent(oDuration, sName) {
  5873. if (oDuration == null)
  5874. return null;
  5875. var nValue = oDuration[sName] * (oDuration.negative ?-1 : 1);
  5876. return sName == "seconds" ? new cXSDecimal(nValue) : new cXSInteger(nValue);
  5877. };
  5878. //
  5879. function fFunction_dateTime_getComponent(oDateTime, sName) {
  5880. if (oDateTime == null)
  5881. return null;
  5882. if (sName == "timezone") {
  5883. var nTimezone = oDateTime.timezone;
  5884. if (nTimezone == null)
  5885. return null;
  5886. return new cXSDayTimeDuration(0, cMath.abs(~~(nTimezone / 60)), cMath.abs(nTimezone % 60), 0, nTimezone < 0);
  5887. }
  5888. else {
  5889. var nValue = oDateTime[sName];
  5890. if (!(oDateTime instanceof cXSDate)) {
  5891. if (sName == "hours")
  5892. if (nValue == 24)
  5893. nValue = 0;
  5894. }
  5895. if (!(oDateTime instanceof cXSTime))
  5896. nValue *= oDateTime.negative ?-1 : 1;
  5897. return sName == "seconds" ? new cXSDecimal(nValue) : new cXSInteger(nValue);
  5898. }
  5899. };
  5900. //
  5901. function fFunction_dateTime_adjustTimezone(oDateTime, oTimezone) {
  5902. if (oDateTime == null)
  5903. return null;
  5904. // Create a copy
  5905. var oValue;
  5906. if (oDateTime instanceof cXSDate)
  5907. oValue = new cXSDate(oDateTime.year, oDateTime.month, oDateTime.day, oDateTime.timezone, oDateTime.negative);
  5908. else
  5909. if (oDateTime instanceof cXSTime)
  5910. oValue = new cXSTime(oDateTime.hours, oDateTime.minutes, oDateTime.seconds, oDateTime.timezone, oDateTime.negative);
  5911. else
  5912. oValue = new cXSDateTime(oDateTime.year, oDateTime.month, oDateTime.day, oDateTime.hours, oDateTime.minutes, oDateTime.seconds, oDateTime.timezone, oDateTime.negative);
  5913. //
  5914. if (oTimezone == null)
  5915. oValue.timezone = null;
  5916. else {
  5917. var nTimezone = fOperator_dayTimeDuration_toSeconds(oTimezone) / 60;
  5918. if (oDateTime.timezone != null) {
  5919. var nDiff = nTimezone - oDateTime.timezone;
  5920. if (oDateTime instanceof cXSDate) {
  5921. if (nDiff < 0)
  5922. oValue.day--;
  5923. }
  5924. else {
  5925. oValue.minutes += nDiff % 60;
  5926. oValue.hours += ~~(nDiff / 60);
  5927. }
  5928. //
  5929. fXSDateTime_normalize(oValue);
  5930. }
  5931. oValue.timezone = nTimezone;
  5932. }
  5933. return oValue;
  5934. };
  5935. /*
  5936. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  5937. *
  5938. * Copyright (c) 2012 Sergey Ilinsky
  5939. * Dual licensed under the MIT and GPL licenses.
  5940. *
  5941. *
  5942. */
  5943. /*
  5944. 14 Functions and Operators on Nodes
  5945. name
  5946. local-name
  5947. namespace-uri
  5948. number
  5949. lang
  5950. root
  5951. */
  5952. // 14 Functions on Nodes
  5953. // fn:name() as xs:string
  5954. // fn:name($arg as node()?) as xs:string
  5955. fStaticContext_defineSystemFunction("name", [[cXTNode, '?', true]], function(oNode) {
  5956. if (!arguments.length) {
  5957. if (!this.DOMAdapter.isNode(this.item))
  5958. throw new cException("XPTY0004"
  5959. );
  5960. oNode = this.item;
  5961. }
  5962. else
  5963. if (oNode == null)
  5964. return new cXSString('');
  5965. //
  5966. var vValue = hStaticContext_functions["node-name"].call(this, oNode);
  5967. return new cXSString(vValue == null ? '' : vValue.toString());
  5968. });
  5969. // fn:local-name() as xs:string
  5970. // fn:local-name($arg as node()?) as xs:string
  5971. fStaticContext_defineSystemFunction("local-name", [[cXTNode, '?', true]], function(oNode) {
  5972. if (!arguments.length) {
  5973. if (!this.DOMAdapter.isNode(this.item))
  5974. throw new cException("XPTY0004"
  5975. );
  5976. oNode = this.item;
  5977. }
  5978. else
  5979. if (oNode == null)
  5980. return new cXSString('');
  5981. //
  5982. return new cXSString(this.DOMAdapter.getProperty(oNode, "localName") || '');
  5983. });
  5984. // fn:namespace-uri() as xs:anyURI
  5985. // fn:namespace-uri($arg as node()?) as xs:anyURI
  5986. fStaticContext_defineSystemFunction("namespace-uri", [[cXTNode, '?', true]], function(oNode) {
  5987. if (!arguments.length) {
  5988. if (!this.DOMAdapter.isNode(this.item))
  5989. throw new cException("XPTY0004"
  5990. );
  5991. oNode = this.item;
  5992. }
  5993. else
  5994. if (oNode == null)
  5995. return cXSAnyURI.cast(new cXSString(''));
  5996. //
  5997. return cXSAnyURI.cast(new cXSString(this.DOMAdapter.getProperty(oNode, "namespaceURI") || ''));
  5998. });
  5999. // fn:number() as xs:double
  6000. // fn:number($arg as xs:anyAtomicType?) as xs:double
  6001. fStaticContext_defineSystemFunction("number", [[cXSAnyAtomicType, '?', true]], function(/*[*/oItem/*]*/) {
  6002. if (!arguments.length) {
  6003. if (!this.item)
  6004. throw new cException("XPDY0002");
  6005. oItem = fFunction_sequence_atomize([this.item], this)[0];
  6006. }
  6007. // If input item cannot be cast to xs:decimal, a NaN should be returned
  6008. var vValue = new cXSDouble(nNaN);
  6009. if (oItem != null) {
  6010. try {
  6011. vValue = cXSDouble.cast(oItem);
  6012. }
  6013. catch (e) {
  6014. }
  6015. }
  6016. return vValue;
  6017. });
  6018. // fn:lang($testlang as xs:string?) as xs:boolean
  6019. // fn:lang($testlang as xs:string?, $node as node()) as xs:boolean
  6020. fStaticContext_defineSystemFunction("lang", [[cXSString, '?'], [cXTNode, '', true]], function(sLang, oNode) {
  6021. if (arguments.length < 2) {
  6022. if (!this.DOMAdapter.isNode(this.item))
  6023. throw new cException("XPTY0004"
  6024. );
  6025. oNode = this.item;
  6026. }
  6027. var fGetProperty = this.DOMAdapter.getProperty;
  6028. if (fGetProperty(oNode, "nodeType") == 2)
  6029. oNode = fGetProperty(oNode, "ownerElement");
  6030. // walk up the tree looking for xml:lang attribute
  6031. for (var aAttributes; oNode; oNode = fGetProperty(oNode, "parentNode"))
  6032. if (aAttributes = fGetProperty(oNode, "attributes"))
  6033. for (var nIndex = 0, nLength = aAttributes.length; nIndex < nLength; nIndex++)
  6034. if (fGetProperty(aAttributes[nIndex], "nodeName") == "xml:lang")
  6035. return new cXSBoolean(fGetProperty(aAttributes[nIndex], "value").replace(/-.+/, '').toLowerCase() == sLang.valueOf().replace(/-.+/, '').toLowerCase());
  6036. //
  6037. return new cXSBoolean(false);
  6038. });
  6039. // fn:root() as node()
  6040. // fn:root($arg as node()?) as node()?
  6041. fStaticContext_defineSystemFunction("root", [[cXTNode, '?', true]], function(oNode) {
  6042. if (!arguments.length) {
  6043. if (!this.DOMAdapter.isNode(this.item))
  6044. throw new cException("XPTY0004"
  6045. );
  6046. oNode = this.item;
  6047. }
  6048. else
  6049. if (oNode == null)
  6050. return null;
  6051. var fGetProperty = this.DOMAdapter.getProperty;
  6052. // If context node is Attribute
  6053. if (fGetProperty(oNode, "nodeType") == 2)
  6054. oNode = fGetProperty(oNode, "ownerElement");
  6055. for (var oParent = oNode; oParent; oParent = fGetProperty(oNode, "parentNode"))
  6056. oNode = oParent;
  6057. return oNode;
  6058. });
  6059. /*
  6060. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  6061. *
  6062. * Copyright (c) 2012 Sergey Ilinsky
  6063. * Dual licensed under the MIT and GPL licenses.
  6064. *
  6065. *
  6066. */
  6067. /*
  6068. 6.4 Functions on Numeric Values
  6069. abs
  6070. ceiling
  6071. floor
  6072. round
  6073. round-half-to-even
  6074. */
  6075. // 6.4 Functions on Numeric Values
  6076. // fn:abs($arg as numeric?) as numeric?
  6077. fStaticContext_defineSystemFunction("abs", [[cXSDouble, '?']], function(oValue) {
  6078. return new cXSDecimal(cMath.abs(oValue));
  6079. });
  6080. // fn:ceiling($arg as numeric?) as numeric?
  6081. fStaticContext_defineSystemFunction("ceiling", [[cXSDouble, '?']], function(oValue) {
  6082. return new cXSDecimal(cMath.ceil(oValue));
  6083. });
  6084. // fn:floor($arg as numeric?) as numeric?
  6085. fStaticContext_defineSystemFunction("floor", [[cXSDouble, '?']], function(oValue) {
  6086. return new cXSDecimal(cMath.floor(oValue));
  6087. });
  6088. // fn:round($arg as numeric?) as numeric?
  6089. fStaticContext_defineSystemFunction("round", [[cXSDouble, '?']], function(oValue) {
  6090. return new cXSDecimal(cMath.round(oValue));
  6091. });
  6092. // fn:round-half-to-even($arg as numeric?) as numeric?
  6093. // fn:round-half-to-even($arg as numeric?, $precision as xs:integer) as numeric?
  6094. fStaticContext_defineSystemFunction("round-half-to-even", [[cXSDouble, '?'], [cXSInteger, '', true]], function(oValue, oPrecision) {
  6095. var nPrecision = arguments.length > 1 ? oPrecision.valueOf() : 0;
  6096. //
  6097. if (nPrecision < 0) {
  6098. var oPower = new cXSInteger(cMath.pow(10,-nPrecision)),
  6099. nRounded= cMath.round(hStaticContext_operators["numeric-divide"].call(this, oValue, oPower)),
  6100. oRounded= new cXSInteger(nRounded);
  6101. nDecimal= cMath.abs(hStaticContext_operators["numeric-subtract"].call(this, oRounded, hStaticContext_operators["numeric-divide"].call(this, oValue, oPower)));
  6102. return hStaticContext_operators["numeric-multiply"].call(this, hStaticContext_operators["numeric-add"].call(this, oRounded, new cXSDecimal(nDecimal == 0.5 && nRounded % 2 ?-1 : 0)), oPower);
  6103. }
  6104. else {
  6105. var oPower = new cXSInteger(cMath.pow(10, nPrecision)),
  6106. nRounded= cMath.round(hStaticContext_operators["numeric-multiply"].call(this, oValue, oPower)),
  6107. oRounded= new cXSInteger(nRounded);
  6108. nDecimal= cMath.abs(hStaticContext_operators["numeric-subtract"].call(this, oRounded, hStaticContext_operators["numeric-multiply"].call(this, oValue, oPower)));
  6109. return hStaticContext_operators["numeric-divide"].call(this, hStaticContext_operators["numeric-add"].call(this, oRounded, new cXSDecimal(nDecimal == 0.5 && nRounded % 2 ?-1 : 0)), oPower);
  6110. }
  6111. });
  6112. /*
  6113. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  6114. *
  6115. * Copyright (c) 2012 Sergey Ilinsky
  6116. * Dual licensed under the MIT and GPL licenses.
  6117. *
  6118. *
  6119. */
  6120. /*
  6121. 11.1 Additional Constructor Functions for QNames
  6122. resolve-QName
  6123. QName
  6124. 11.2 Functions and Operators Related to QNames
  6125. prefix-from-QName
  6126. local-name-from-QName
  6127. namespace-uri-from-QName
  6128. namespace-uri-for-prefix
  6129. in-scope-prefixes
  6130. */
  6131. // 11.1 Additional Constructor Functions for QNames
  6132. // fn:resolve-QName($qname as xs:string?, $element as element()) as xs:QName?
  6133. fStaticContext_defineSystemFunction("resolve-QName", [[cXSString, '?'], [cXTElement]], function(oQName, oElement) {
  6134. if (oQName == null)
  6135. return null;
  6136. var sQName = oQName.valueOf(),
  6137. aMatch = sQName.match(rXSQName);
  6138. if (!aMatch)
  6139. throw new cException("FOCA0002"
  6140. );
  6141. var sPrefix = aMatch[1] || null,
  6142. sLocalName = aMatch[2],
  6143. sNameSpaceURI = this.DOMAdapter.lookupNamespaceURI(oElement, sPrefix);
  6144. //
  6145. if (sPrefix != null &&!sNameSpaceURI)
  6146. throw new cException("FONS0004"
  6147. );
  6148. return new cXSQName(sPrefix, sLocalName, sNameSpaceURI || null);
  6149. });
  6150. // fn:QName($paramURI as xs:string?, $paramQName as xs:string) as xs:QName
  6151. fStaticContext_defineSystemFunction("QName", [[cXSString, '?'], [cXSString]], function(oUri, oQName) {
  6152. var sQName = oQName.valueOf(),
  6153. aMatch = sQName.match(rXSQName);
  6154. if (!aMatch)
  6155. throw new cException("FOCA0002"
  6156. );
  6157. return new cXSQName(aMatch[1] || null, aMatch[2] || null, oUri == null ? '' : oUri.valueOf());
  6158. });
  6159. // 11.2 Functions Related to QNames
  6160. // fn:prefix-from-QName($arg as xs:QName?) as xs:NCName?
  6161. fStaticContext_defineSystemFunction("prefix-from-QName", [[cXSQName, '?']], function(oQName) {
  6162. if (oQName != null) {
  6163. if (oQName.prefix)
  6164. return new cXSNCName(oQName.prefix);
  6165. }
  6166. //
  6167. return null;
  6168. });
  6169. // fn:local-name-from-QName($arg as xs:QName?) as xs:NCName?
  6170. fStaticContext_defineSystemFunction("local-name-from-QName", [[cXSQName, '?']], function(oQName) {
  6171. if (oQName == null)
  6172. return null;
  6173. return new cXSNCName(oQName.localName);
  6174. });
  6175. // fn:namespace-uri-from-QName($arg as xs:QName?) as xs:anyURI?
  6176. fStaticContext_defineSystemFunction("namespace-uri-from-QName", [[cXSQName, '?']], function(oQName) {
  6177. if (oQName == null)
  6178. return null;
  6179. return cXSAnyURI.cast(new cXSString(oQName.namespaceURI || ''));
  6180. });
  6181. // fn:namespace-uri-for-prefix($prefix as xs:string?, $element as element()) as xs:anyURI?
  6182. fStaticContext_defineSystemFunction("namespace-uri-for-prefix", [[cXSString, '?'], [cXTElement]], function(oPrefix, oElement) {
  6183. var sPrefix = oPrefix == null ? '' : oPrefix.valueOf(),
  6184. sNameSpaceURI = this.DOMAdapter.lookupNamespaceURI(oElement, sPrefix || null);
  6185. return sNameSpaceURI == null ? null : cXSAnyURI.cast(new cXSString(sNameSpaceURI));
  6186. });
  6187. // fn:in-scope-prefixes($element as element()) as xs:string*
  6188. fStaticContext_defineSystemFunction("in-scope-prefixes", [[cXTElement]], function(oElement) {
  6189. throw "Function '" + "in-scope-prefixes" + "' not implemented";
  6190. });
  6191. /*
  6192. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  6193. *
  6194. * Copyright (c) 2012 Sergey Ilinsky
  6195. * Dual licensed under the MIT and GPL licenses.
  6196. *
  6197. *
  6198. */
  6199. /*
  6200. 15.1 General Functions and Operators on Sequences
  6201. boolean
  6202. index-of
  6203. empty
  6204. exists
  6205. distinct-values
  6206. insert-before
  6207. remove
  6208. reverse
  6209. subsequence
  6210. unordered
  6211. 15.2 Functions That Test the Cardinality of Sequences
  6212. zero-or-one
  6213. one-or-more
  6214. exactly-one
  6215. 15.3 Equals, Union, Intersection and Except
  6216. deep-equal
  6217. 15.4 Aggregate Functions
  6218. count
  6219. avg
  6220. max
  6221. min
  6222. sum
  6223. 15.5 Functions and Operators that Generate Sequences
  6224. id
  6225. idref
  6226. doc
  6227. doc-available
  6228. collection
  6229. element-with-id
  6230. */
  6231. // 15.1 General Functions and Operators on Sequences
  6232. // fn:boolean($arg as item()*) as xs:boolean
  6233. fStaticContext_defineSystemFunction("boolean", [[cXTItem, '*']], function(oSequence1) {
  6234. return new cXSBoolean(fFunction_sequence_toEBV(oSequence1, this));
  6235. });
  6236. // fn:index-of($seqParam as xs:anyAtomicType*, $srchParam as xs:anyAtomicType) as xs:integer*
  6237. // fn:index-of($seqParam as xs:anyAtomicType*, $srchParam as xs:anyAtomicType, $collation as xs:string) as xs:integer*
  6238. fStaticContext_defineSystemFunction("index-of", [[cXSAnyAtomicType, '*'], [cXSAnyAtomicType], [cXSString, '', true]], function(oSequence1, oSearch, oCollation) {
  6239. if (!oSequence1.length || oSearch == null)
  6240. return [];
  6241. // TODO: Implement collation
  6242. var vLeft = oSearch;
  6243. // Cast to XSString if Untyped
  6244. if (vLeft instanceof cXSUntypedAtomic)
  6245. vLeft = cXSString.cast(vLeft);
  6246. var oSequence = [];
  6247. for (var nIndex = 0, nLength = oSequence1.length, vRight; nIndex < nLength; nIndex++) {
  6248. vRight = oSequence1[nIndex];
  6249. // Cast to XSString if Untyped
  6250. if (vRight instanceof cXSUntypedAtomic)
  6251. vRight = cXSString.cast(vRight);
  6252. //
  6253. if (vRight.valueOf() === vLeft.valueOf())
  6254. oSequence.push(new cXSInteger(nIndex + 1));
  6255. }
  6256. return oSequence;
  6257. });
  6258. // fn:empty($arg as item()*) as xs:boolean
  6259. fStaticContext_defineSystemFunction("empty", [[cXTItem, '*']], function(oSequence1) {
  6260. return new cXSBoolean(!oSequence1.length);
  6261. });
  6262. // fn:exists($arg as item()*) as xs:boolean
  6263. fStaticContext_defineSystemFunction("exists", [[cXTItem, '*']], function(oSequence1) {
  6264. return new cXSBoolean(!!oSequence1.length);
  6265. });
  6266. // fn:distinct-values($arg as xs:anyAtomicType*) as xs:anyAtomicType*
  6267. // fn:distinct-values($arg as xs:anyAtomicType*, $collation as xs:string) as xs:anyAtomicType*
  6268. fStaticContext_defineSystemFunction("distinct-values", [[cXSAnyAtomicType, '*'], [cXSString, '', true]], function(oSequence1, oCollation) {
  6269. if (arguments.length > 1)
  6270. throw "Collation parameter in function '" + "distinct-values" + "' is not implemented";
  6271. if (!oSequence1.length)
  6272. return null;
  6273. var oSequence = [];
  6274. for (var nIndex = 0, nLength = oSequence1.length, vLeft; nIndex < nLength; nIndex++) {
  6275. vLeft = oSequence1[nIndex];
  6276. // Cast to XSString if Untyped
  6277. if (vLeft instanceof cXSUntypedAtomic)
  6278. vLeft = cXSString.cast(vLeft);
  6279. for (var nRightIndex = 0, nRightLength = oSequence.length, vRight, bFound = false; (nRightIndex < nRightLength) &&!bFound; nRightIndex++) {
  6280. vRight = oSequence[nRightIndex];
  6281. // Cast to XSString if Untyped
  6282. if (vRight instanceof cXSUntypedAtomic)
  6283. vRight = cXSString.cast(vRight);
  6284. //
  6285. if (vRight.valueOf() === vLeft.valueOf())
  6286. bFound = true;
  6287. }
  6288. if (!bFound)
  6289. oSequence.push(oSequence1[nIndex]);
  6290. }
  6291. return oSequence;
  6292. });
  6293. // fn:insert-before($target as item()*, $position as xs:integer, $inserts as item()*) as item()*
  6294. fStaticContext_defineSystemFunction("insert-before", [[cXTItem, '*'], [cXSInteger], [cXTItem, '*']], function(oSequence1, oPosition, oSequence3) {
  6295. if (!oSequence1.length)
  6296. return oSequence3;
  6297. if (!oSequence3.length)
  6298. return oSequence1;
  6299. var nLength = oSequence1.length,
  6300. nPosition = oPosition.valueOf();
  6301. if (nPosition < 1)
  6302. nPosition = 1;
  6303. else
  6304. if (nPosition > nLength)
  6305. nPosition = nLength + 1;
  6306. var oSequence = [];
  6307. for (var nIndex = 0; nIndex < nLength; nIndex++) {
  6308. if (nPosition == nIndex + 1)
  6309. oSequence = oSequence.concat(oSequence3);
  6310. oSequence.push(oSequence1[nIndex]);
  6311. }
  6312. if (nPosition == nIndex + 1)
  6313. oSequence = oSequence.concat(oSequence3);
  6314. return oSequence;
  6315. });
  6316. // fn:remove($target as item()*, $position as xs:integer) as item()*
  6317. fStaticContext_defineSystemFunction("remove", [[cXTItem, '*'], [cXSInteger]], function(oSequence1, oPosition) {
  6318. if (!oSequence1.length)
  6319. return [];
  6320. var nLength = oSequence1.length,
  6321. nPosition = oPosition.valueOf();
  6322. if (nPosition < 1 || nPosition > nLength)
  6323. return oSequence1;
  6324. var oSequence = [];
  6325. for (var nIndex = 0; nIndex < nLength; nIndex++)
  6326. if (nPosition != nIndex + 1)
  6327. oSequence.push(oSequence1[nIndex]);
  6328. return oSequence;
  6329. });
  6330. // fn:reverse($arg as item()*) as item()*
  6331. fStaticContext_defineSystemFunction("reverse", [[cXTItem, '*']], function(oSequence1) {
  6332. oSequence1.reverse();
  6333. return oSequence1;
  6334. });
  6335. // fn:subsequence($sourceSeq as item()*, $startingLoc as xs:double) as item()*
  6336. // fn:subsequence($sourceSeq as item()*, $startingLoc as xs:double, $length as xs:double) as item()*
  6337. fStaticContext_defineSystemFunction("subsequence", [[cXTItem, '*'], [cXSDouble, ''], [cXSDouble, '', true]], function(oSequence1, oStart, oLength) {
  6338. var nPosition = cMath.round(oStart),
  6339. nLength = arguments.length > 2 ? cMath.round(oLength) : oSequence1.length - nPosition + 1;
  6340. // TODO: Handle out-of-range position and length values
  6341. return oSequence1.slice(nPosition - 1, nPosition - 1 + nLength);
  6342. });
  6343. // fn:unordered($sourceSeq as item()*) as item()*
  6344. fStaticContext_defineSystemFunction("unordered", [[cXTItem, '*']], function(oSequence1) {
  6345. return oSequence1;
  6346. });
  6347. // 15.2 Functions That Test the Cardinality of Sequences
  6348. // fn:zero-or-one($arg as item()*) as item()?
  6349. fStaticContext_defineSystemFunction("zero-or-one", [[cXTItem, '*']], function(oSequence1) {
  6350. if (oSequence1.length > 1)
  6351. throw new cException("FORG0003");
  6352. return oSequence1;
  6353. });
  6354. // fn:one-or-more($arg as item()*) as item()+
  6355. fStaticContext_defineSystemFunction("one-or-more", [[cXTItem, '*']], function(oSequence1) {
  6356. if (!oSequence1.length)
  6357. throw new cException("FORG0004");
  6358. return oSequence1;
  6359. });
  6360. // fn:exactly-one($arg as item()*) as item()
  6361. fStaticContext_defineSystemFunction("exactly-one", [[cXTItem, '*']], function(oSequence1) {
  6362. if (oSequence1.length != 1)
  6363. throw new cException("FORG0005");
  6364. return oSequence1;
  6365. });
  6366. // 15.3 Equals, Union, Intersection and Except
  6367. // fn:deep-equal($parameter1 as item()*, $parameter2 as item()*) as xs:boolean
  6368. // fn:deep-equal($parameter1 as item()*, $parameter2 as item()*, $collation as string) as xs:boolean
  6369. fStaticContext_defineSystemFunction("deep-equal", [[cXTItem, '*'], [cXTItem, '*'], [cXSString, '', true]], function(oSequence1, oSequence2, oCollation) {
  6370. throw "Function '" + "deep-equal" + "' not implemented";
  6371. });
  6372. // 15.4 Aggregate Functions
  6373. // fn:count($arg as item()*) as xs:integer
  6374. fStaticContext_defineSystemFunction("count", [[cXTItem, '*']], function(oSequence1) {
  6375. return new cXSInteger(oSequence1.length);
  6376. });
  6377. // fn:avg($arg as xs:anyAtomicType*) as xs:anyAtomicType?
  6378. fStaticContext_defineSystemFunction("avg", [[cXSAnyAtomicType, '*']], function(oSequence1) {
  6379. if (!oSequence1.length)
  6380. return null;
  6381. //
  6382. try {
  6383. var vValue = oSequence1[0];
  6384. if (vValue instanceof cXSUntypedAtomic)
  6385. vValue = cXSDouble.cast(vValue);
  6386. for (var nIndex = 1, nLength = oSequence1.length, vRight; nIndex < nLength; nIndex++) {
  6387. vRight = oSequence1[nIndex];
  6388. if (vRight instanceof cXSUntypedAtomic)
  6389. vRight = cXSDouble.cast(vRight);
  6390. vValue = hAdditiveExpr_operators['+'](vValue, vRight, this);
  6391. }
  6392. return hMultiplicativeExpr_operators['div'](vValue, new cXSInteger(nLength), this);
  6393. }
  6394. catch (e) {
  6395. // XPTY0004: Arithmetic operator is not defined for provided arguments
  6396. throw e.code != "XPTY0004" ? e : new cException("FORG0006"
  6397. );
  6398. }
  6399. });
  6400. // fn:max($arg as xs:anyAtomicType*) as xs:anyAtomicType?
  6401. // fn:max($arg as xs:anyAtomicType*, $collation as string) as xs:anyAtomicType?
  6402. fStaticContext_defineSystemFunction("max", [[cXSAnyAtomicType, '*'], [cXSString, '', true]], function(oSequence1, oCollation) {
  6403. if (!oSequence1.length)
  6404. return null;
  6405. // TODO: Implement collation
  6406. //
  6407. try {
  6408. var vValue = oSequence1[0];
  6409. if (vValue instanceof cXSUntypedAtomic)
  6410. vValue = cXSDouble.cast(vValue);
  6411. for (var nIndex = 1, nLength = oSequence1.length, vRight; nIndex < nLength; nIndex++) {
  6412. vRight = oSequence1[nIndex];
  6413. if (vRight instanceof cXSUntypedAtomic)
  6414. vRight = cXSDouble.cast(vRight);
  6415. if (hComparisonExpr_ValueComp_operators['ge'](vRight, vValue, this).valueOf())
  6416. vValue = vRight;
  6417. }
  6418. return vValue;
  6419. }
  6420. catch (e) {
  6421. // XPTY0004: Cannot compare {type1} with {type2}
  6422. throw e.code != "XPTY0004" ? e : new cException("FORG0006"
  6423. );
  6424. }
  6425. });
  6426. // fn:min($arg as xs:anyAtomicType*) as xs:anyAtomicType?
  6427. // fn:min($arg as xs:anyAtomicType*, $collation as string) as xs:anyAtomicType?
  6428. fStaticContext_defineSystemFunction("min", [[cXSAnyAtomicType, '*'], [cXSString, '', true]], function(oSequence1, oCollation) {
  6429. if (!oSequence1.length)
  6430. return null;
  6431. // TODO: Implement collation
  6432. //
  6433. try {
  6434. var vValue = oSequence1[0];
  6435. if (vValue instanceof cXSUntypedAtomic)
  6436. vValue = cXSDouble.cast(vValue);
  6437. for (var nIndex = 1, nLength = oSequence1.length, vRight; nIndex < nLength; nIndex++) {
  6438. vRight = oSequence1[nIndex];
  6439. if (vRight instanceof cXSUntypedAtomic)
  6440. vRight = cXSDouble.cast(vRight);
  6441. if (hComparisonExpr_ValueComp_operators['le'](vRight, vValue, this).valueOf())
  6442. vValue = vRight;
  6443. }
  6444. return vValue;
  6445. }
  6446. catch (e) {
  6447. // Cannot compare {type1} with {type2}
  6448. throw e.code != "XPTY0004" ? e : new cException("FORG0006"
  6449. );
  6450. }
  6451. });
  6452. // fn:sum($arg as xs:anyAtomicType*) as xs:anyAtomicType
  6453. // fn:sum($arg as xs:anyAtomicType*, $zero as xs:anyAtomicType?) as xs:anyAtomicType?
  6454. fStaticContext_defineSystemFunction("sum", [[cXSAnyAtomicType, '*'], [cXSAnyAtomicType, '?', true]], function(oSequence1, oZero) {
  6455. if (!oSequence1.length) {
  6456. if (arguments.length > 1)
  6457. return oZero;
  6458. else
  6459. return new cXSDouble(0);
  6460. return null;
  6461. }
  6462. // TODO: Implement collation
  6463. //
  6464. try {
  6465. var vValue = oSequence1[0];
  6466. if (vValue instanceof cXSUntypedAtomic)
  6467. vValue = cXSDouble.cast(vValue);
  6468. for (var nIndex = 1, nLength = oSequence1.length, vRight; nIndex < nLength; nIndex++) {
  6469. vRight = oSequence1[nIndex];
  6470. if (vRight instanceof cXSUntypedAtomic)
  6471. vRight = cXSDouble.cast(vRight);
  6472. vValue = hAdditiveExpr_operators['+'](vValue, vRight, this);
  6473. }
  6474. return vValue;
  6475. }
  6476. catch (e) {
  6477. // XPTY0004: Arithmetic operator is not defined for provided arguments
  6478. throw e.code != "XPTY0004" ? e : new cException("FORG0006"
  6479. );
  6480. }
  6481. });
  6482. // 15.5 Functions and Operators that Generate Sequences
  6483. // fn:id($arg as xs:string*) as element()*
  6484. // fn:id($arg as xs:string*, $node as node()) as element()*
  6485. fStaticContext_defineSystemFunction("id", [[cXSString, '*'], [cXTNode, '', true]], function(oSequence1, oNode) {
  6486. if (arguments.length < 2) {
  6487. if (!this.DOMAdapter.isNode(this.item))
  6488. throw new cException("XPTY0004"
  6489. );
  6490. oNode = this.item;
  6491. }
  6492. // Get root node and check if it is Document
  6493. var oDocument = hStaticContext_functions["root"].call(this, oNode);
  6494. if (this.DOMAdapter.getProperty(oDocument, "nodeType") != 9)
  6495. throw new cException("FODC0001");
  6496. // Search for elements
  6497. var oSequence = [];
  6498. for (var nIndex = 0; nIndex < oSequence1.length; nIndex++)
  6499. for (var nRightIndex = 0, aValue = fString_trim(oSequence1[nIndex]).split(/\s+/), nRightLength = aValue.length; nRightIndex < nRightLength; nRightIndex++)
  6500. if ((oNode = this.DOMAdapter.getElementById(oDocument, aValue[nRightIndex])) && fArray_indexOf(oSequence, oNode) ==-1)
  6501. oSequence.push(oNode);
  6502. //
  6503. return fFunction_sequence_order(oSequence, this);
  6504. });
  6505. // fn:idref($arg as xs:string*) as node()*
  6506. // fn:idref($arg as xs:string*, $node as node()) as node()*
  6507. fStaticContext_defineSystemFunction("idref", [[cXSString, '*'], [cXTNode, '', true]], function(oSequence1, oNode) {
  6508. throw "Function '" + "idref" + "' not implemented";
  6509. });
  6510. // fn:doc($uri as xs:string?) as document-node()?
  6511. fStaticContext_defineSystemFunction("doc", [[cXSString, '?', true]], function(oUri) {
  6512. throw "Function '" + "doc" + "' not implemented";
  6513. });
  6514. // fn:doc-available($uri as xs:string?) as xs:boolean
  6515. fStaticContext_defineSystemFunction("doc-available", [[cXSString, '?', true]], function(oUri) {
  6516. throw "Function '" + "doc-available" + "' not implemented";
  6517. });
  6518. // fn:collection() as node()*
  6519. // fn:collection($arg as xs:string?) as node()*
  6520. fStaticContext_defineSystemFunction("collection", [[cXSString, '?', true]], function(oUri) {
  6521. throw "Function '" + "collection" + "' not implemented";
  6522. });
  6523. // fn:element-with-id($arg as xs:string*) as element()*
  6524. // fn:element-with-id($arg as xs:string*, $node as node()) as element()*
  6525. fStaticContext_defineSystemFunction("element-with-id", [[cXSString, '*'], [cXTNode, '', true]], function(oSequence1, oNode) {
  6526. throw "Function '" + "element-with-id" + "' not implemented";
  6527. });
  6528. // EBV calculation
  6529. function fFunction_sequence_toEBV(oSequence1, oContext) {
  6530. if (!oSequence1.length)
  6531. return false;
  6532. var oItem = oSequence1[0];
  6533. if (oContext.DOMAdapter.isNode(oItem))
  6534. return true;
  6535. if (oSequence1.length == 1) {
  6536. if (oItem instanceof cXSBoolean)
  6537. return oItem.value.valueOf();
  6538. if (oItem instanceof cXSString)
  6539. return !!oItem.valueOf().length;
  6540. if (fXSAnyAtomicType_isNumeric(oItem))
  6541. return !(fIsNaN(oItem.valueOf()) || oItem.valueOf() == 0);
  6542. throw new cException("FORG0006"
  6543. );
  6544. }
  6545. throw new cException("FORG0006"
  6546. );
  6547. };
  6548. function fFunction_sequence_atomize(oSequence1, oContext) {
  6549. var oSequence = [];
  6550. for (var nIndex = 0, nLength = oSequence1.length, oItem, vItem; nIndex < nLength; nIndex++) {
  6551. oItem = oSequence1[nIndex];
  6552. vItem = null;
  6553. // Untyped
  6554. if (oItem == null)
  6555. vItem = null;
  6556. // Node type
  6557. else
  6558. if (oContext.DOMAdapter.isNode(oItem)) {
  6559. var fGetProperty = oContext.DOMAdapter.getProperty;
  6560. switch (fGetProperty(oItem, "nodeType")) {
  6561. case 1: // ELEMENT_NODE
  6562. vItem = new cXSUntypedAtomic(fGetProperty(oItem, "textContent"));
  6563. break;
  6564. case 2: // ATTRIBUTE_NODE
  6565. vItem = new cXSUntypedAtomic(fGetProperty(oItem, "value"));
  6566. break;
  6567. case 3: // TEXT_NODE
  6568. case 4: // CDATA_SECTION_NODE
  6569. case 8: // COMMENT_NODE
  6570. vItem = new cXSUntypedAtomic(fGetProperty(oItem, "data"));
  6571. break;
  6572. case 7: // PROCESSING_INSTRUCTION_NODE
  6573. vItem = new cXSUntypedAtomic(fGetProperty(oItem, "data"));
  6574. break;
  6575. case 9: // DOCUMENT_NODE
  6576. var oNode = fGetProperty(oItem, "documentElement");
  6577. vItem = new cXSUntypedAtomic(oNode ? fGetProperty(oNode, "textContent") : '');
  6578. break;
  6579. }
  6580. }
  6581. // Base types
  6582. else
  6583. if (oItem instanceof cXSAnyAtomicType)
  6584. vItem = oItem;
  6585. //
  6586. if (vItem != null)
  6587. oSequence.push(vItem);
  6588. }
  6589. return oSequence;
  6590. };
  6591. // Orders items in sequence in document order
  6592. function fFunction_sequence_order(oSequence1, oContext) {
  6593. return oSequence1.sort(function(oNode, oNode2) {
  6594. var nPosition = oContext.DOMAdapter.compareDocumentPosition(oNode, oNode2);
  6595. return nPosition & 2 ? 1 : nPosition & 4 ?-1 : 0;
  6596. });
  6597. };
  6598. /*
  6599. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  6600. *
  6601. * Copyright (c) 2012 Sergey Ilinsky
  6602. * Dual licensed under the MIT and GPL licenses.
  6603. *
  6604. *
  6605. */
  6606. /*
  6607. 7.2 Functions to Assemble and Disassemble Strings
  6608. codepoints-to-string
  6609. string-to-codepoints
  6610. 7.3 Equality and Comparison of Strings
  6611. compare
  6612. codepoint-equal
  6613. 7.4 Functions on String Values
  6614. concat
  6615. string-join
  6616. substring
  6617. string-length
  6618. normalize-space
  6619. normalize-unicode
  6620. upper-case
  6621. lower-case
  6622. translate
  6623. encode-for-uri
  6624. iri-to-uri
  6625. escape-html-uri
  6626. 7.5 Functions Based on Substring Matching
  6627. contains
  6628. starts-with
  6629. ends-with
  6630. substring-before
  6631. substring-after
  6632. 7.6 String Functions that Use Pattern Matching
  6633. matches
  6634. replace
  6635. tokenize
  6636. */
  6637. // 7.2 Functions to Assemble and Disassemble Strings
  6638. // fn:codepoints-to-string($arg as xs:integer*) as xs:string
  6639. fStaticContext_defineSystemFunction("codepoints-to-string", [[cXSInteger, '*']], function(oSequence1) {
  6640. var aValue = [];
  6641. for (var nIndex = 0, nLength = oSequence1.length; nIndex < nLength; nIndex++)
  6642. aValue.push(cString.fromCharCode(oSequence1[nIndex]));
  6643. return new cXSString(aValue.join(''));
  6644. });
  6645. // fn:string-to-codepoints($arg as xs:string?) as xs:integer*
  6646. fStaticContext_defineSystemFunction("string-to-codepoints", [[cXSString, '?']], function(oValue) {
  6647. if (oValue == null)
  6648. return null;
  6649. var sValue = oValue.valueOf();
  6650. if (sValue == '')
  6651. return [];
  6652. var oSequence = [];
  6653. for (var nIndex = 0, nLength = sValue.length; nIndex < nLength; nIndex++)
  6654. oSequence.push(new cXSInteger(sValue.charCodeAt(nIndex)));
  6655. return oSequence;
  6656. });
  6657. // 7.3 Equality and Comparison of Strings
  6658. // fn:compare($comparand1 as xs:string?, $comparand2 as xs:string?) as xs:integer?
  6659. // fn:compare($comparand1 as xs:string?, $comparand2 as xs:string?, $collation as xs:string) as xs:integer?
  6660. fStaticContext_defineSystemFunction("compare", [[cXSString, '?'], [cXSString, '?'], [cXSString, '', true]], function(oValue1, oValue2, oCollation) {
  6661. if (oValue1 == null || oValue2 == null)
  6662. return null;
  6663. var sCollation = this.staticContext.defaultCollationName,
  6664. vCollation;
  6665. if (arguments.length > 2)
  6666. sCollation = oCollation.valueOf();
  6667. vCollation = sCollation == sNS_XPF + "/collation/codepoint" ? oCodepointStringCollator : this.staticContext.getCollation(sCollation);
  6668. if (!vCollation)
  6669. throw new cException("FOCH0002"
  6670. );
  6671. return new cXSInteger(vCollation.compare(oValue1.valueOf(), oValue2.valueOf()));
  6672. });
  6673. // fn:codepoint-equal($comparand1 as xs:string?, $comparand2 as xs:string?) as xs:boolean?
  6674. fStaticContext_defineSystemFunction("codepoint-equal", [[cXSString, '?'], [cXSString, '?']], function(oValue1, oValue2) {
  6675. if (oValue1 == null || oValue2 == null)
  6676. return null;
  6677. // TODO: Check if JS uses 'Unicode code point collation' here
  6678. return new cXSBoolean(oValue1.valueOf() == oValue2.valueOf());
  6679. });
  6680. // 7.4 Functions on String Values
  6681. // fn:concat($arg1 as xs:anyAtomicType?, $arg2 as xs:anyAtomicType?, ...) as xs:string
  6682. fStaticContext_defineSystemFunction("concat", null, function() {
  6683. // check arguments length
  6684. if (arguments.length < 2)
  6685. throw new cException("XPST0017"
  6686. );
  6687. var aValue = [];
  6688. for (var nIndex = 0, nLength = arguments.length, oSequence; nIndex < nLength; nIndex++) {
  6689. oSequence = arguments[nIndex];
  6690. // Assert cardinality
  6691. fFunctionCall_assertSequenceCardinality(this, oSequence, '?'
  6692. );
  6693. //
  6694. if (oSequence.length)
  6695. aValue[aValue.length] = cXSString.cast(fFunction_sequence_atomize(oSequence, this)[0]).valueOf();
  6696. }
  6697. return new cXSString(aValue.join(''));
  6698. });
  6699. // fn:string-join($arg1 as xs:string*, $arg2 as xs:string) as xs:string
  6700. fStaticContext_defineSystemFunction("string-join", [[cXSString, '*'], [cXSString]], function(oSequence1, oValue) {
  6701. return new cXSString(oSequence1.join(oValue));
  6702. });
  6703. // fn:substring($sourceString as xs:string?, $startingLoc as xs:double) as xs:string
  6704. // fn:substring($sourceString as xs:string?, $startingLoc as xs:double, $length as xs:double) as xs:string
  6705. fStaticContext_defineSystemFunction("substring", [[cXSString, '?'], [cXSDouble], [cXSDouble, '', true]], function(oValue, oStart, oLength) {
  6706. var sValue = oValue == null ? '' : oValue.valueOf(),
  6707. nStart = cMath.round(oStart) - 1,
  6708. nEnd = arguments.length > 2 ? nStart + cMath.round(oLength) : sValue.length;
  6709. // TODO: start can be negative
  6710. return new cXSString(nEnd > nStart ? sValue.substring(nStart, nEnd) : '');
  6711. });
  6712. // fn:string-length() as xs:integer
  6713. // fn:string-length($arg as xs:string?) as xs:integer
  6714. fStaticContext_defineSystemFunction("string-length", [[cXSString, '?', true]], function(oValue) {
  6715. if (!arguments.length) {
  6716. if (!this.item)
  6717. throw new cException("XPDY0002");
  6718. oValue = cXSString.cast(fFunction_sequence_atomize([this.item], this)[0]);
  6719. }
  6720. return new cXSInteger(oValue == null ? 0 : oValue.valueOf().length);
  6721. });
  6722. // fn:normalize-space() as xs:string
  6723. // fn:normalize-space($arg as xs:string?) as xs:string
  6724. fStaticContext_defineSystemFunction("normalize-space", [[cXSString, '?', true]], function(oValue) {
  6725. if (!arguments.length) {
  6726. if (!this.item)
  6727. throw new cException("XPDY0002");
  6728. oValue = cXSString.cast(fFunction_sequence_atomize([this.item], this)[0]);
  6729. }
  6730. return new cXSString(oValue == null ? '' : fString_trim(oValue).replace(/\s\s+/g, ' '));
  6731. });
  6732. // fn:normalize-unicode($arg as xs:string?) as xs:string
  6733. // fn:normalize-unicode($arg as xs:string?, $normalizationForm as xs:string) as xs:string
  6734. fStaticContext_defineSystemFunction("normalize-unicode", [[cXSString, '?'], [cXSString, '', true]], function(oValue, oNormalization) {
  6735. throw "Function '" + "normalize-unicode" + "' not implemented";
  6736. });
  6737. // fn:upper-case($arg as xs:string?) as xs:string
  6738. fStaticContext_defineSystemFunction("upper-case", [[cXSString, '?']], function(oValue) {
  6739. return new cXSString(oValue == null ? '' : oValue.valueOf().toUpperCase());
  6740. });
  6741. // fn:lower-case($arg as xs:string?) as xs:string
  6742. fStaticContext_defineSystemFunction("lower-case", [[cXSString, '?']], function(oValue) {
  6743. return new cXSString(oValue == null ? '' : oValue.valueOf().toLowerCase());
  6744. });
  6745. // fn:translate($arg as xs:string?, $mapString as xs:string, $transString as xs:string) as xs:string
  6746. fStaticContext_defineSystemFunction("translate", [[cXSString, '?'], [cXSString], [cXSString]], function(oValue, oMap, oTranslate) {
  6747. if (oValue == null)
  6748. return new cXSString('');
  6749. var aValue = oValue.valueOf().split(''),
  6750. aMap = oMap.valueOf().split(''),
  6751. aTranslate = oTranslate.valueOf().split(''),
  6752. nTranslateLength = aTranslate.length,
  6753. aReturn = [];
  6754. for (var nIndex = 0, nLength = aValue.length, nPosition; nIndex < nLength; nIndex++)
  6755. if ((nPosition = aMap.indexOf(aValue[nIndex])) ==-1)
  6756. aReturn[aReturn.length] = aValue[nIndex];
  6757. else
  6758. if (nPosition < nTranslateLength)
  6759. aReturn[aReturn.length] = aTranslate[nPosition];
  6760. return new cXSString(aReturn.join(''));
  6761. });
  6762. // fn:encode-for-uri($uri-part as xs:string?) as xs:string
  6763. fStaticContext_defineSystemFunction("encode-for-uri", [[cXSString, '?']], function(oValue) {
  6764. return new cXSString(oValue == null ? '' : window.encodeURIComponent(oValue));
  6765. });
  6766. // fn:iri-to-uri($iri as xs:string?) as xs:string
  6767. fStaticContext_defineSystemFunction("iri-to-uri", [[cXSString, '?']], function(oValue) {
  6768. return new cXSString(oValue == null ? '' : window.encodeURI(window.decodeURI(oValue)));
  6769. });
  6770. // fn:escape-html-uri($uri as xs:string?) as xs:string
  6771. fStaticContext_defineSystemFunction("escape-html-uri", [[cXSString, '?']], function(oValue) {
  6772. if (oValue == null || oValue.valueOf() == '')
  6773. return new cXSString('');
  6774. // Encode
  6775. var aValue = oValue.valueOf().split('');
  6776. for (var nIndex = 0, nLength = aValue.length, nCode; nIndex < nLength; nIndex++)
  6777. if ((nCode = aValue[nIndex].charCodeAt(0)) < 32 || nCode > 126)
  6778. aValue[nIndex] = window.encodeURIComponent(aValue[nIndex]);
  6779. return new cXSString(aValue.join(''));
  6780. });
  6781. // 7.5 Functions Based on Substring Matching
  6782. // fn:contains($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean
  6783. // fn:contains($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean
  6784. fStaticContext_defineSystemFunction("contains", [[cXSString, '?'], [cXSString, '?'], [cXSString, '', true]], function(oValue, oSearch, oCollation) {
  6785. if (arguments.length > 2)
  6786. throw "Collation parameter in function '" + "contains" + "' is not implemented";
  6787. return new cXSBoolean((oValue == null ? '' : oValue.valueOf()).indexOf(oSearch == null ? '' : oSearch.valueOf()) >= 0);
  6788. });
  6789. // fn:starts-with($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean
  6790. // fn:starts-with($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean
  6791. fStaticContext_defineSystemFunction("starts-with", [[cXSString, '?'], [cXSString, '?'], [cXSString, '', true]], function(oValue, oSearch, oCollation) {
  6792. if (arguments.length > 2)
  6793. throw "Collation parameter in function '" + "starts-with" + "' is not implemented";
  6794. return new cXSBoolean((oValue == null ? '' : oValue.valueOf()).indexOf(oSearch == null ? '' : oSearch.valueOf()) == 0);
  6795. });
  6796. // fn:ends-with($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean
  6797. // fn:ends-with($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean
  6798. fStaticContext_defineSystemFunction("ends-with", [[cXSString, '?'], [cXSString, '?'], [cXSString, '', true]], function(oValue, oSearch, oCollation) {
  6799. if (arguments.length > 2)
  6800. throw "Collation parameter in function '" + "ends-with" + "' is not implemented";
  6801. var sValue = oValue == null ? '' : oValue.valueOf(),
  6802. sSearch = oSearch == null ? '' : oSearch.valueOf();
  6803. return new cXSBoolean(sValue.indexOf(sSearch) == sValue.length - sSearch.length);
  6804. });
  6805. // fn:substring-before($arg1 as xs:string?, $arg2 as xs:string?) as xs:string
  6806. // fn:substring-before($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:string
  6807. fStaticContext_defineSystemFunction("substring-before", [[cXSString, '?'], [cXSString, '?'], [cXSString, '', true]], function(oValue, oSearch, oCollation) {
  6808. if (arguments.length > 2)
  6809. throw "Collation parameter in function '" + "substring-before" + "' is not implemented";
  6810. var sValue = oValue == null ? '' : oValue.valueOf(),
  6811. sSearch = oSearch == null ? '' : oSearch.valueOf(),
  6812. nPosition;
  6813. return new cXSString((nPosition = sValue.indexOf(sSearch)) >= 0 ? sValue.substring(0, nPosition) : '');
  6814. });
  6815. // fn:substring-after($arg1 as xs:string?, $arg2 as xs:string?) as xs:string
  6816. // fn:substring-after($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:string
  6817. fStaticContext_defineSystemFunction("substring-after", [[cXSString, '?'], [cXSString, '?'], [cXSString, '', true]], function(oValue, oSearch, oCollation) {
  6818. if (arguments.length > 2)
  6819. throw "Collation parameter in function '" + "substring-after" + "' is not implemented";
  6820. var sValue = oValue == null ? '' : oValue.valueOf(),
  6821. sSearch = oSearch == null ? '' : oSearch.valueOf(),
  6822. nPosition;
  6823. return new cXSString((nPosition = sValue.indexOf(sSearch)) >= 0 ? sValue.substring(nPosition + sSearch.length) : '');
  6824. });
  6825. // 7.6 String Functions that Use Pattern Matching
  6826. function fFunction_string_createRegExp(sValue, sFlags) {
  6827. var d1 = '\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF',
  6828. d2 = '\u0370-\u037D\u037F-\u1FFF\u200C-\u200D',
  6829. d3 = '\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD',
  6830. c = 'A-Z_a-z\\-.0-9\u00B7' + d1 + '\u0300-\u036F' + d2 + '\u203F-\u2040' + d3,
  6831. i = 'A-Z_a-z' + d1 + d2 + d3;
  6832. sValue = sValue
  6833. .replace(/\[\\i-\[:\]\]/g, '[' + i + ']')
  6834. .replace(/\[\\c-\[:\]\]/g, '[' + c + ']')
  6835. .replace(/\\i/g, '[:' + i + ']')
  6836. .replace(/\\I/g, '[^:' + i + ']')
  6837. .replace(/\\c/g, '[:' + c + ']')
  6838. .replace(/\\C/g, '[^:' + c + ']');
  6839. // Check if all flags are legal
  6840. if (sFlags && !sFlags.match(/^[smix]+$/))
  6841. throw new cException("FORX0001"); // Invalid character '{%0}' in regular expression flags
  6842. var bFlagS = sFlags.indexOf('s') >= 0,
  6843. bFlagX = sFlags.indexOf('x') >= 0;
  6844. if (bFlagS || bFlagX) {
  6845. // Strip 's' and 'x' from flags
  6846. sFlags = sFlags.replace(/[sx]/g, '');
  6847. var aValue = [],
  6848. rValue = /\s/;
  6849. for (var nIndex = 0, nLength = sValue.length, bValue = false, sCharCurr, sCharPrev = ''; nIndex < nLength; nIndex++) {
  6850. sCharCurr = sValue.charAt(nIndex);
  6851. if (sCharPrev != '\\') {
  6852. if (sCharCurr == '[')
  6853. bValue = true;
  6854. else
  6855. if (sCharCurr == ']')
  6856. bValue = false;
  6857. }
  6858. // Replace '\s' for flag 'x' if not in []
  6859. if (bValue || !(bFlagX && rValue.test(sCharCurr))) {
  6860. // Replace '.' for flag 's' if not in []
  6861. if (!bValue && (bFlagS && sCharCurr == '.' && sCharPrev != '\\'))
  6862. aValue[aValue.length] = '(?:.|\\s)';
  6863. else
  6864. aValue[aValue.length] = sCharCurr;
  6865. }
  6866. sCharPrev = sCharCurr;
  6867. }
  6868. sValue = aValue.join('');
  6869. }
  6870. return new cRegExp(sValue, sFlags + 'g');
  6871. };
  6872. // fn:matches($input as xs:string?, $pattern as xs:string) as xs:boolean
  6873. // fn:matches($input as xs:string?, $pattern as xs:string, $flags as xs:string) as xs:boolean
  6874. fStaticContext_defineSystemFunction("matches", [[cXSString, '?'], [cXSString], [cXSString, '', true]], function(oValue, oPattern, oFlags) {
  6875. var sValue = oValue == null ? '' : oValue.valueOf(),
  6876. rRegExp = fFunction_string_createRegExp(oPattern.valueOf(), arguments.length > 2 ? oFlags.valueOf() : '');
  6877. return new cXSBoolean(rRegExp.test(sValue));
  6878. });
  6879. // fn:replace($input as xs:string?, $pattern as xs:string, $replacement as xs:string) as xs:string
  6880. // fn:replace($input as xs:string?, $pattern as xs:string, $replacement as xs:string, $flags as xs:string) as xs:string
  6881. fStaticContext_defineSystemFunction("replace", [[cXSString, '?'], [cXSString], [cXSString], [cXSString, '', true]], function(oValue, oPattern, oReplacement, oFlags) {
  6882. var sValue = oValue == null ? '' : oValue.valueOf(),
  6883. rRegExp = fFunction_string_createRegExp(oPattern.valueOf(), arguments.length > 3 ? oFlags.valueOf() : '');
  6884. return new cXSBoolean(sValue.replace(rRegExp, oReplacement.valueOf()));
  6885. });
  6886. // fn:tokenize($input as xs:string?, $pattern as xs:string) as xs:string*
  6887. // fn:tokenize($input as xs:string?, $pattern as xs:string, $flags as xs:string) as xs:string*
  6888. fStaticContext_defineSystemFunction("tokenize", [[cXSString, '?'], [cXSString], [cXSString, '', true]], function(oValue, oPattern, oFlags) {
  6889. var sValue = oValue == null ? '' : oValue.valueOf(),
  6890. rRegExp = fFunction_string_createRegExp(oPattern.valueOf(), arguments.length > 2 ? oFlags.valueOf() : '');
  6891. var oSequence = [];
  6892. for (var nIndex = 0, aValue = sValue.split(rRegExp), nLength = aValue.length; nIndex < nLength; nIndex++)
  6893. oSequence.push(new cXSString(aValue[nIndex]));
  6894. return oSequence;
  6895. });
  6896. /*
  6897. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  6898. *
  6899. * Copyright (c) 2012 Sergey Ilinsky
  6900. * Dual licensed under the MIT and GPL licenses.
  6901. *
  6902. *
  6903. */
  6904. /*
  6905. 4 The Trace Function
  6906. trace
  6907. */
  6908. // fn:trace($value as item()*, $label as xs:string) as item()*
  6909. fStaticContext_defineSystemFunction("trace", [[cXTItem, '*'], [cXSString]], function(oSequence1, oLabel) {
  6910. var oConsole = window.console;
  6911. if (oConsole && oConsole.log)
  6912. oConsole.log(oLabel.valueOf(), oSequence1);
  6913. return oSequence1;
  6914. });
  6915. /*
  6916. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  6917. *
  6918. * Copyright (c) 2012 Sergey Ilinsky
  6919. * Dual licensed under the MIT and GPL licenses.
  6920. *
  6921. *
  6922. */
  6923. var oCodepointStringCollator = new cStringCollator;
  6924. oCodepointStringCollator.equals = function(sValue1, sValue2) {
  6925. return sValue1 == sValue2;
  6926. };
  6927. oCodepointStringCollator.compare = function(sValue1, sValue2) {
  6928. return sValue1 == sValue2 ? 0 : sValue1 > sValue2 ? 1 :-1;
  6929. };
  6930. function cLXDOMAdapter() {
  6931. };
  6932. cLXDOMAdapter.prototype = new cDOMAdapter;
  6933. var oLXDOMAdapter_staticContext = new cStaticContext;
  6934. cLXDOMAdapter.prototype.getProperty = function(oNode, sName) {
  6935. if (sName in oNode)
  6936. return oNode[sName];
  6937. if (sName == "baseURI") {
  6938. var sBaseURI = '',
  6939. fResolveUri = oLXDOMAdapter_staticContext.getFunction('{' + "http://www.w3.org/2005/xpath-functions" + '}' + "resolve-uri"),
  6940. cXSString = oLXDOMAdapter_staticContext.getDataType('{' + "http://www.w3.org/2001/XMLSchema" + '}' + "string");
  6941. for (var oParent = oNode, sUri; oParent; oParent = oParent.parentNode)
  6942. if (oParent.nodeType == 1 && (sUri = oParent.getAttribute("xml:base")))
  6943. sBaseURI = fResolveUri(new cXSString(sUri), new cXSString(sBaseURI)).toString();
  6944. return sBaseURI;
  6945. }
  6946. else
  6947. if (sName == "textContent") {
  6948. var aText = [];
  6949. (function(oNode) {
  6950. for (var nIndex = 0, oChild; oChild = oNode.childNodes[nIndex]; nIndex++)
  6951. if (oChild.nodeType == 3 || oChild.nodeType == 4 )
  6952. aText.push(oChild.data);
  6953. else
  6954. if (oChild.nodeType == 1 && oChild.firstChild)
  6955. arguments.callee(oChild);
  6956. })(oNode);
  6957. return aText.join('');
  6958. }
  6959. };
  6960. cLXDOMAdapter.prototype.compareDocumentPosition = function(oNode, oChild) {
  6961. if ("compareDocumentPosition" in oNode)
  6962. return oNode.compareDocumentPosition(oChild);
  6963. if (oChild == oNode)
  6964. return 0;
  6965. var oAttr1 = null,
  6966. oAttr2 = null,
  6967. aAttributes,
  6968. oAttr, oElement, nIndex, nLength;
  6969. if (oNode.nodeType == 2 ) {
  6970. oAttr1 = oNode;
  6971. oNode = this.getProperty(oAttr1, "ownerElement");
  6972. }
  6973. if (oChild.nodeType == 2 ) {
  6974. oAttr2 = oChild;
  6975. oChild = this.getProperty(oAttr2, "ownerElement");
  6976. }
  6977. if (oAttr1 && oAttr2 && oNode && oNode == oChild) {
  6978. for (nIndex = 0, aAttributes = this.getProperty(oNode, "attributes"), nLength = aAttributes.length; nIndex < nLength; nIndex++) {
  6979. oAttr = aAttributes[nIndex];
  6980. if (oAttr == oAttr1)
  6981. return 32 | 4 ;
  6982. if (oAttr == oAttr2)
  6983. return 32 | 2 ;
  6984. }
  6985. }
  6986. var aChain1 = [], nLength1, oNode1,
  6987. aChain2 = [], nLength2, oNode2;
  6988. if (oAttr1)
  6989. aChain1.push(oAttr1);
  6990. for (oElement = oNode; oElement; oElement = oElement.parentNode)
  6991. aChain1.push(oElement);
  6992. if (oAttr2)
  6993. aChain2.push(oAttr2);
  6994. for (oElement = oChild; oElement; oElement = oElement.parentNode)
  6995. aChain2.push(oElement);
  6996. if (((oNode.ownerDocument || oNode) != (oChild.ownerDocument || oChild)) || (aChain1[aChain1.length - 1] != aChain2[aChain2.length - 1]))
  6997. return 32 | 1 ;
  6998. for (nIndex = cMath.min(nLength1 = aChain1.length, nLength2 = aChain2.length); nIndex; --nIndex)
  6999. if ((oNode1 = aChain1[--nLength1]) != (oNode2 = aChain2[--nLength2])) {
  7000. if (oNode1.nodeType == 2 )
  7001. return 4 ;
  7002. if (oNode2.nodeType == 2 )
  7003. return 2 ;
  7004. if (!oNode2.nextSibling)
  7005. return 4 ;
  7006. if (!oNode1.nextSibling)
  7007. return 2 ;
  7008. for (oElement = oNode2.previousSibling; oElement; oElement = oElement.previousSibling)
  7009. if (oElement == oNode1)
  7010. return 4 ;
  7011. return 2 ;
  7012. }
  7013. return nLength1 < nLength2 ? 4 | 16 : 2 | 8 ;
  7014. };
  7015. cLXDOMAdapter.prototype.lookupNamespaceURI = function(oNode, sPrefix) {
  7016. if ("lookupNamespaceURI" in oNode)
  7017. return oNode.lookupNamespaceURI(sPrefix);
  7018. for (; oNode && oNode.nodeType != 9 ; oNode = oNode.parentNode)
  7019. if (sPrefix == this.getProperty(oChild, "prefix"))
  7020. return this.getProperty(oNode, "namespaceURI");
  7021. else
  7022. if (oNode.nodeType == 1) for (var oAttributes = this.getProperty(oNode, "attributes"), nIndex = 0, nLength = oAttributes.length, sName = "xmlns" + ':' + sPrefix; nIndex < nLength; nIndex++)
  7023. if (this.getProperty(oAttributes[nIndex], "nodeName") == sName)
  7024. return this.getProperty(oAttributes[nIndex], "value");
  7025. return null;
  7026. };
  7027. cLXDOMAdapter.prototype.getElementsByTagNameNS = function(oNode, sNameSpaceURI, sLocalName) {
  7028. if ("getElementsByTagNameNS" in oNode)
  7029. return oNode.getElementsByTagNameNS(sNameSpaceURI, sLocalName);
  7030. var aElements = [],
  7031. bNameSpaceURI = '*' == sNameSpaceURI,
  7032. bLocalName = '*' == sLocalName;
  7033. (function(oNode) {
  7034. for (var nIndex = 0, oChild; oChild = oNode.childNodes[nIndex]; nIndex++)
  7035. if (oChild.nodeType == 1) { if ((bLocalName || sLocalName == this.getProperty(oChild, "localName")) && (bNameSpaceURI || sNameSpaceURI == this.getProperty(oChild, "namespaceURI")))
  7036. aElements[aElements.length] = oChild;
  7037. if (oChild.firstChild)
  7038. arguments.callee(oChild);
  7039. }
  7040. })(oNode);
  7041. return aElements;
  7042. };
  7043. var oMSHTMLDOMAdapter = new cLXDOMAdapter;
  7044. oMSHTMLDOMAdapter.getProperty = function(oNode, sName) {
  7045. if (sName == "localName") {
  7046. if (oNode.nodeType == 1)
  7047. return oNode.nodeName.toLowerCase();
  7048. }
  7049. if (sName == "prefix")
  7050. return null;
  7051. if (sName == "namespaceURI")
  7052. return oNode.nodeType == 1 ? "http://www.w3.org/1999/xhtml" : null;
  7053. if (sName == "textContent")
  7054. return oNode.innerText;
  7055. if (sName == "attributes" && oNode.nodeType == 1) {
  7056. var aAttributes = [];
  7057. for (var nIndex = 0, oAttributes = oNode.attributes, nLength = oAttributes.length, oNode2, oAttribute; nIndex < nLength; nIndex++) {
  7058. oNode2 = oAttributes[nIndex];
  7059. if (oNode2.specified) {
  7060. oAttribute = new cAttr;
  7061. oAttribute.ownerElement = oNode;
  7062. oAttribute.ownerDocument= oNode.ownerDocument;
  7063. oAttribute.specified = true;
  7064. oAttribute.value =
  7065. oAttribute.nodeValue = oNode2.nodeValue;
  7066. oAttribute.name =
  7067. oAttribute.nodeName =
  7068. oAttribute.localName = oNode2.nodeName.toLowerCase();
  7069. aAttributes[aAttributes.length] = oAttribute;
  7070. }
  7071. }
  7072. return aAttributes;
  7073. }
  7074. return cLXDOMAdapter.prototype.getProperty.call(this, oNode, sName);
  7075. };
  7076. var oMSXMLDOMAdapter = new cLXDOMAdapter;
  7077. oMSXMLDOMAdapter.getProperty = function(oNode, sName) {
  7078. if (sName == "localName") {
  7079. if (oNode.nodeType == 7)
  7080. return null;
  7081. if (oNode.nodeType == 1)
  7082. return oNode.baseName;
  7083. }
  7084. if (sName == "prefix" || sName == "namespaceURI")
  7085. return oNode[sName] || null;
  7086. if (sName == "textContent")
  7087. return oNode.text;
  7088. if (sName == "attributes" && oNode.nodeType == 1) {
  7089. var aAttributes = [];
  7090. for (var nIndex = 0, oAttributes = oNode.attributes, nLength = oAttributes.length, oNode2, oAttribute; nIndex < nLength; nIndex++) {
  7091. oNode2 = oAttributes[nIndex];
  7092. if (oNode2.specified) {
  7093. oAttribute = new cAttr;
  7094. oAttribute.nodeType = 2;
  7095. oAttribute.ownerElement = oNode;
  7096. oAttribute.ownerDocument= oNode.ownerDocument;
  7097. oAttribute.specified = true;
  7098. oAttribute.value =
  7099. oAttribute.nodeValue = oNode2.nodeValue;
  7100. oAttribute.name =
  7101. oAttribute.nodeName = oNode2.nodeName;
  7102. oAttribute.localName = oNode2.baseName;
  7103. oAttribute.prefix = oNode2.prefix || null;
  7104. oAttribute.namespaceURI = oNode2.namespaceURI || null;
  7105. aAttributes[aAttributes.length] = oAttribute;
  7106. }
  7107. }
  7108. return aAttributes;
  7109. }
  7110. return cLXDOMAdapter.prototype.getProperty.call(this, oNode, sName);
  7111. };
  7112. oMSXMLDOMAdapter.getElementById = function(oDocument, sId) {
  7113. return oDocument.nodeFromID(sId);
  7114. };
  7115. function cEvaluator() {
  7116. };
  7117. cEvaluator.prototype.defaultOL2DOMAdapter = new cLXDOMAdapter;
  7118. cEvaluator.prototype.defaultOL2HTMLDOMAdapter = new cLXDOMAdapter;
  7119. cEvaluator.prototype.defaultHTMLStaticContext = new cStaticContext;
  7120. cEvaluator.prototype.defaultHTMLStaticContext.baseURI = window.document.location.href;
  7121. cEvaluator.prototype.defaultHTMLStaticContext.defaultFunctionNamespace = "http://www.w3.org/2005/xpath-functions";
  7122. cEvaluator.prototype.defaultHTMLStaticContext.defaultElementNamespace = "http://www.w3.org/1999/xhtml";
  7123. cEvaluator.prototype.defaultXMLStaticContext = new cStaticContext;
  7124. cEvaluator.prototype.defaultXMLStaticContext.defaultFunctionNamespace = "http://www.w3.org/2005/xpath-functions";
  7125. cEvaluator.prototype.bOldMS = !!window.document.namespaces && !window.document.createElementNS;
  7126. cEvaluator.prototype.bOldW3 = !cEvaluator.prototype.bOldMS && window.document.documentElement.namespaceURI != "http://www.w3.org/1999/xhtml";
  7127. cEvaluator.prototype.defaultDOMAdapter = new cDOMAdapter;
  7128. cEvaluator.prototype.compile = function(sExpression, oStaticContext) {
  7129. return new cExpression(sExpression, oStaticContext);
  7130. };
  7131. cEvaluator.prototype.evaluate = function(oQuery, sExpression, fNSResolver) {
  7132. if (! (oQuery instanceof window.jQuery))
  7133. oQuery = new window.jQuery(oQuery)
  7134. if (typeof sExpression == "undefined" || sExpression === null)
  7135. sExpression = '';
  7136. var oNode = oQuery[0];
  7137. if (typeof oNode == "undefined")
  7138. oNode = null;
  7139. var oStaticContext = oNode && (oNode.nodeType == 9 ? oNode : oNode.ownerDocument).createElement("div").tagName == "DIV" ? this.defaultHTMLStaticContext : this.defaultXMLStaticContext;
  7140. oStaticContext.namespaceResolver = fNSResolver;
  7141. var oExpression = new cExpression(cString(sExpression), oStaticContext);
  7142. oStaticContext.namespaceResolver = null;
  7143. var aSequence,
  7144. oSequence = new window.jQuery,
  7145. oAdapter = this.defaultOL2DOMAdapter;
  7146. if (this.bOldMS)
  7147. oAdapter = oStaticContext == this.defaultHTMLStaticContext ? oMSHTMLDOMAdapter : oMSXMLDOMAdapter;
  7148. else
  7149. if (this.bOldW3 && oStaticContext == this.defaultHTMLStaticContext)
  7150. oAdapter = this.defaultOL2HTMLDOMAdapter;
  7151. aSequence = oExpression.evaluate(new cDynamicContext(oStaticContext, oNode, null, oAdapter));
  7152. for (var nIndex = 0, nLength = aSequence.length, oItem; nIndex < nLength; nIndex++)
  7153. oSequence.push(oAdapter.isNode(oItem = aSequence[nIndex]) ? oItem : cStaticContext.xs2js(oItem));
  7154. return oSequence;
  7155. };
  7156. /*
  7157. * XPath.js - Pure JavaScript implementation of XPath 2.0 parser and evaluator
  7158. *
  7159. * Copyright (c) 2012 Sergey Ilinsky
  7160. * Dual licensed under the MIT and GPL licenses.
  7161. *
  7162. *
  7163. */
  7164. var oXPathEvaluator = new cEvaluator,
  7165. oXPathClasses = oXPathEvaluator.classes = {};
  7166. //
  7167. oXPathClasses.Exception = cException;
  7168. oXPathClasses.Expression = cExpression;
  7169. oXPathClasses.DOMAdapter = cDOMAdapter;
  7170. oXPathClasses.StaticContext = cStaticContext;
  7171. oXPathClasses.DynamicContext= cDynamicContext;
  7172. oXPathClasses.StringCollator= cStringCollator;
  7173. // Publish object
  7174. window.xpath = oXPathEvaluator;
  7175. })()