Thank You so much. It worked like a charm.

————————————————
Kashif Khan, PMI-ACP
Sr. Solution Architect
Publishing Technology

Houghton Mifflin Harcourt
9400 South Park Center Loop
Orlando, FL 32819
Office: 407.345.3420
Mobile: 407.949.4697
hmhco.com

From: David Lee <[email protected]<mailto:[email protected]>>
Date: Tuesday, May 28, 2013 12:49 PM
To: Kashif Khan <[email protected]<mailto:[email protected]>>, 
"[email protected]<mailto:[email protected]>" 
<[email protected]<mailto:[email protected]>>
Subject: RE: Unable to get the value of Element

In pure XQuery what  you are attempting will not work ... xpath cannot have an 
accessor element which is dynamic ...
but you can do something similar.

Note: The following is hand typed by memory , might have typos.  Also this 
assumes your document is in no namespace.
Changes need to be made to accomidate namespaces.

First off you want to return a QName not an element for getHierarchyElements



declare function oxy:getHierarchyElements() as xs:QName {


let $TagName := "Chapter Title"


        (:removing the space between Chapter and Title:)
      let $tokenizedString := fn:tokenize(($TagName), '\s')
        let $concatString :=  fn:concat($tokenizedString[1], 
$tokenizedString[2])
         return
            fn:QName("",$concatString() )
};


Then you need to change your xpath to use node-name



declare function oxy:getLevel($document as xs:string){
    let $file := doc($document)
    let $hierarchy := oxy:getHierarchyElements()
    return
            $file/report/body/row/*[ node-name(.) eq $hierarchy ]
};





----------------------------------------
David A. Lee
[email protected]<mailto:[email protected]>
http://www.xmlsh.org

From: [email protected]<mailto:[email protected]> 
[mailto:[email protected]] On Behalf Of Khan, Kashif
Sent: Tuesday, May 28, 2013 12:43 PM
To: [email protected]<mailto:[email protected]>
Subject: [xquery-talk] Unable to get the value of Element

Hello Everyone, I am having a problem extracting value from an element
Here is the XML on which I am trying to run my query


Let $document := "<report>
        <body>
        <row>
            <ChapterTitle>Front Matter</ChapterTitle>
</row

</body>

</report>"



These are the functions that I have written to extract the value of the 
"ChapterTitle" Tag



declare function oxy:getHierarchyElements() {


let $TagName := "Chapter Title"


        (:removing the space between Chapter and Title:)

let $tokenizedString := fn:tokenize(($TagName), '\s')
        let $concatString :=  fn:concat($tokenizedString[1], 
$tokenizedString[2])
         return
            element {$concatString} {''}

};

declare function oxy:getLevel($document as xs:string){
    let $file := doc($document)
    let $hierarchy := oxy:getHierarchyElements()
    return
            $file/report/body/row/$hierarchy
};



When I call oxy:getLevel($oxy:document) I get <ChapterTitle/>  instead of 
"Front Matter" from the XML file.



If I replace   $file/report/body/row/$hierarchy with  
$file/report/body/row/ChapterTitle I get the correct value.


Thanks for your help in advance

————————————————
Kashif Khan
_______________________________________________
[email protected]
http://x-query.com/mailman/listinfo/talk

Reply via email to