I think I wasn't clear enough in my example, and confused you further by using the 'local' prefix. Let's take a simpler example:

  <test xmlns="abc">{ collection()/x/y/z }</test>

In this query, /x/y/z will select elements with local-names x, y, and z, *in* the "abc" namespace. If x, y, and z are actually in the empty namespace, they won't match. I believe this is the problem you're facing.

To fix this, we can move the namespace-sensitive XPath outside the scope of the xmlns declaration.

let $val := collection()/x/y/z
return <test xmlns="abc">{ $val }</test>

Now the XPath uses the empty namespace, and we can refer to its bound variable, $val, in the enclosed expression.

Does that help?

-- Mike

Mindie Sorenson wrote:
I'm still having a problem with this.  I have adjusted my code so that it 
follows Mike's suggestions and also has my getTeasers function inline and not 
in another module (which is where I'd ideally like it to be).  However, 
although I can see the results, I still can't access specific elements (such as 
title, text, etc.) within the resultset.  I understand that my results are in 
the default namespace, but I haven't found a way to access them directly.  Does 
anyone know how to do this?

Here is my code:

xquery version "1.0-ml";

import module namespace common = "commonFunctions" at 
"../modules/commonFunctions.xqy";

declare variable $pageName := "labs";
declare variable $locale := xdmp:get-request-field( "locale" , "eng");
declare variable $src := xdmp:get-request-field( "src", "02285");


declare function local:getTeasers( $locale, $type, $pageName ) {
    let $teasers := /[EMAIL PROTECTED] = $locale]/[EMAIL PROTECTED] = 
$type][page = $pageName]
    return $teasers
};

xdmp:set-response-content-type( "text/html" ),
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>',

let $righSashTeasers := common:getTeasers( $locale, "Right Sash", $pageName )
return

<html xmlns="http://www.w3.org/1999/xhtml";>
        <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" 
/>
                <title>{ common:getString($locale, $pageName, "webIndexTitle") 
}</title>
                <link rel="stylesheet" href="css/reset.css" type="text/css" media="screen" 
title="no title" charset="utf-8" />
                <!--[if IE]><link rel="stylesheet" href="conference/css/ie.css" type="text/css" 
media="screen, projection"><![endif]-->
                <link rel="stylesheet" href="css/home.css" type="text/css" media="screen" 
title="no title" charset="utf-8" />
                <link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css" 
media="screen" />
                <link rel="stylesheet" href="css/labs.css" type="text/css" media="screen" 
title="no title" charset="utf-8" />
                <script type="text/javascript" 
src="/web/script/omniture.js"></script>
                <script src="script/jquery-1.2.1.pack.js" 
type="text/javascript"></script>
        <!--[if lte IE 6]><script src="script/jquery.bgiframe.min.js" 
type="text/javascript"></script><![endif]-->
        <script src="script/jquery.autocomplete.packed.js" 
type="text/javascript"></script>

        <script src="conference/script/project.js" type="text/javascript" 
charset="utf-8"></script>
        <script src="conference/script/browse.js" type="text/javascript" 
charset="utf-8"></script>
        </head>
        <body id="labs">
           <div id="main" class="clearfix">
                        <div id="labs-featured">
                                <div id="labs-welcome">
                                        <h1>{ common:getString($locale, $pageName, 
"welcome") }</h1>
                                        <p>{ common:getString($locale, $pageName, 
"description") }</p>
                </div>
                <span>
                                {
                                    let $featureTeasers := local:getTeasers( $locale, 
"Feature", $pageName )
                                    for $teaser in local:$featureTeasers
                                    let $mindie := xdmp:log($featureTeasers)
                        let $title as xs:string? := $teaser/local:title
                    let $teaserText as xs:string? := $teaser/local:text
                        let $imageName as xs:string? := $teaser/local:image
                        let $url as xs:string? := $teaser/local:url
                        order by xs:integer($teaser/@sequence) ascending
                        return
                        <div class="featured clearfix">
                                <a href="{ $url }"><img src="images/{ $imageName 
}"/></a>
                                <h3><a href="{ $url }">{ $title}</a></h3>
                                <p>{ $teaserText }</p>
                        </div>
                }
                </span>

                        </div>
                        <div id="latest-news">
                                <h2>{ common:getString($locale, $pageName, 
"latestUpdates") }</h2>
                                { common:getTeasers($locale, "Right Sash", 
$pageName) }
                        </div>
                </div>

        </body>
</html>

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Michael Blakeley
Sent: Friday, September 26, 2008 4:13 PM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] namespace problem

Mindie,

I'd avoid setting the default element namespace in a prolog, like that.
Instead, try something like this (porting to xquery 0.9-ml is left as an
exercise):

xquery version "1.0-ml";

declare variable $METADATA as element() :=
    <meta><title>this is the title</title></meta>
;

declare function local:get-title($m as element(meta))
   as xs:string
{
    $m/title
};

<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<title>{ local:get-title($METADATA) }</title>
</head>
<body>
<p>this is a test</p>
</body>
</html>

Since local:get-title is outside the scope of the html xmlns decl, it
uses the default element namespace, which is still the empty namespace.

-- Mike

Mindie Sorenson wrote:
I have a .xqy file that calls the getTeasers function in the common module:

default element namespace="http://www.w3.org/1999/xhtml";
import module namespace common = "commonFunctions" at 
"../modules/commonFunctions.xqy"

let $featureTeasers := common:getTeasers( $locale, "Feature", $pageName )


I then try to iterate over the results, but I get nothing back except xml.  I'm 
pretty sure it is because the results are in a different namespace, but I can't 
find out how to access them in the correct namespace in my for loop.

<div id="labs-featured">
                        <div id="labs-welcome">
                              <h1>{ common:getString($locale, $pageName, "welcome") 
}</h1>
                              <p>{ common:getString($locale, $pageName, 
"description") }</p>
                </div>
                        {
                    for $teaser in $featureTeasers/teaser
                    let $title as xs:string? := $teaser/title
                        let $teaserText as xs:string? := $teaser/text
                        let $imageName as xs:string? := $teaser/image
                        let $url as xs:string? := $teaser/url
                        order by xs:integer($teaser/@sequence) ascending
                      return $title
                }

                  </div>

Can anyone help?

Thanks
Mindie

----------------------------------------------------------------------
NOTICE: This email message is for the sole use of the intended recipient(s) and 
may contain confidential and privileged information. Any unauthorized review, 
use, disclosure or distribution is prohibited. If you are not the intended 
recipient, please contact the sender by reply email and destroy all copies of 
the original message.



------------------------------------------------------------------------

_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

----------------------------------------------------------------------
NOTICE: This email message is for the sole use of the intended recipient(s) and 
may contain confidential and privileged information. Any unauthorized review, 
use, disclosure or distribution is prohibited. If you are not the intended 
recipient, please contact the sender by reply email and destroy all copies of 
the original message.


------------------------------------------------------------------------

_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to