XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Allan GravesSubject: User functions
Author: Allan Graves
Date: 02 Feb 2005 04:33 PM
Using this XQuery:

(: XQUERY to identify diamonds and display specifics in
an Affiliate XML RAW data feed file :)

declare function local:remove-zeros($data as element) as string {
let $retVal := translate($data,'0',' ')
return string($retVal)
};


<Root>
{
for $offer in /ROOT/Offer
where ($offer/MD_ID = '3')
order by substring($offer/Item_Number, 1,2)
return <Diamond>
{$offer/Item_Number}
<Shape> {substring($offer/Item_Number, 1,2)} </Shape>
<Size> {substring($offer/Item_Number, 9,2)}.{substring($offer/Item_Number, 11,2)} </Size>
<Color>{substring($offer/Item_Number, 19,1)}</Color>
<Clarity>{remove-zeros(substring($offer/Item_Number, 14,4))}</Clarity>
</Diamond>
}


</Root>

I continue to get the following error:
Function 'remove-zeros' in namespace 'http://www.w3.org/2004/10/xpath-functions' is undefined

What am I missing?

Postnext
Alberto MassariSubject: User functions
Author: Alberto Massari
Date: 02 Feb 2005 05:10 PM
Hi Allan,
you should fully qualify the remove-zero function invocation, like this

<Clarity>{local:remove-zeros(substring($offer/Item_Number, 14,4))}</Clarity>

If you don't specify the namespace prefix, the default function namespace
will be used, and by default this is the namespace for the built-in functions.

Hope this helps,
Alberto

Postnext
Allan GravesSubject: User functions
Author: Allan Graves
Date: 02 Feb 2005 05:40 PM
Thank you for your assistance. Adding local: prior to the function call
fixed that particular problem, however, I am now receiving an XP0006 (type)
error.

I changed the function expect string data, and the call is parsing string
data. I don't know what the problem is.

----- Changed XQuery --------
(: XQUERY to identify diamonds and display specifics in
an Affiliate XML RAW data feed file :)

declare function local:remove-zeros($data as string) as string {
let $retVal := $data (: translate($data,"0"," ") :)
return string($data)
};


<Root>
{
for $offer in /ROOT/Offer
where ($offer/MD_ID = '3')
order by substring($offer/Item_Number, 1,2)
return <Diamond>
{$offer/Item_Number}
<Shape> {substring($offer/Item_Number, 1,2)} </Shape>
<Size> {substring($offer/Item_Number, 9,2)}.{substring($offer/Item_Number, 11,2)} </Size>
<Color>{substring($offer/Item_Number, 19,1)}</Color>
<Clarity>{local:remove-zeros(substring($offer/Item_Number, 14,4))}</Clarity>
</Diamond>
}


</Root>

Postnext
Alberto MassariSubject: User functions
Author: Alberto Massari
Date: 03 Feb 2005 03:27 AM
Hi Allan,
the error is generated by the fact that you defined the signature for the
user-defined function using "string" as data type. By not using a namespace
prefix, you are telling that the definition for "string" should be taken
from the default element/type namespace, that by default is empty.
So you should change the definition to be

declare function local:remove-zeros($data as xs:string) as xs:string

Hope this helps,
Alberto

Posttop
Allan GravesSubject: User functions
Author: Allan Graves
Date: 03 Feb 2005 09:37 AM
Thank you. Using xs:string did the trick.

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.