samsons17 -4 Posting Whiz in Training

I have this XML data which basically to add/minus/multiply the two numbers. And I have this Xquery function that suppose to convert this XML data into a readable string format.

For example, let say XML file has in this form :

<expr>
    <add> 
     <number>2</number>
     <number>3</number> 
    </add>
</expr>
<expr>
    <divide>
        <number>7</number>
        <times>
            <number>1</number>
            <number>6</number>
        </times>
    </divide>
</expr>

the Xquery function will be able to convert this into "2 + 3" and 7 / (1 * 6) respectively through the local:convertExpr function

Below is the sample of the Xquery that I am working right now :

Xquery File :

declare function local:convertExpr($expr) {
    (: function to convert XML into a readable string format :)

    let $number := data($expr[1])

    let $x := $number
    return $x
};

validate{<html>
    <head>
        <title>{/*/q:title/text()}</title>
        <script type="text/javascript" src="miniformvalidator.js"/>
    </head>
    <body>
        <h1>{/*/q:title/text()}</h1>
        <form>
            <ol>
            {
                let $exprs := /*/q:expr, 
                    $count := count($exprs)
                 for $i in (1 to $count)
                 let $expr := $exprs[$i]
                 return <li>{local:convertExpr($expr)}</li>
            }
            </ol>
        </form>

    </body>
</html>}

I am able to pull all the numbers within the tags right now, but I am not sure how I can connect these numbers to become one readable string.

Please help. Thanks! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.