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
David CostelloeSubject: Adding embedded functions
Author: David Costelloe
Date: 14 May 2008 09:15 AM
Hi,
I am working with Xpath and newbie. Is it possible to add multi-Xpath functions to a query.

I am looking up multiple returns and would like to use lower-case and return the value as well as true or false?

<vendorFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<fileList>
<file>
<fileName>myfilename6.doc</fileName>
<sequence>A0103</sequence>
<fullPath>/Prices/myfilename6.doc</fullPath>
</file>
<file>
<fileName>myfilename5.doc</fileName>
<sequence>A0104</sequence>
<fullPath>/Prices/myfilename5.doc</fullPath>
</file>
<file>
<fileName>myfilename4.skp</fileName>
<sequence>A0105</sequence>
<fullPath>/Prices/myfilename4.SKP</fullPath>
</file>
<file>
<fileName>myfilename3.doc</fileName>
<sequence>A0106</sequence>
<fullPath>/Prices/myfilename3.doc</fullPath>
</file>
<file>
<fileName>MYFILENAME2.DOC</fileName>
<sequence>A0107</sequence>
<fullPath>/Prices/MYFILENAME2.DOC</fullPath>
</file>
<file>
<fileName>myfilename1.doc</fileName>
<sequence>A0108</sequence>
<fullPath>/Prices/myfilename1.doc</fullPath>
</file>
</fileList>
</vendorFile>

The query I am using:
/vendorFile/fileList/file/fullPath[ends-with(.,'skp')]

I would like to return the value of true or false and the fullPath and convert the lookup to lower-case. is this possible?

Any help would be appreciated.

Thanks

Postnext
Minollo I.Subject: Adding embedded functions
Author: Minollo I.
Date: 14 May 2008 02:04 PM
>The query I am using:
>/vendorFile/fileList/file/fullPath[ends-with(.,'skp')]
>
>I would like to return the value of true or false and the fullPath
>and convert the lookup to lower-case. is this possible?

I'm not sure I understand your question.
You expression above will return all the fullPath elements whose value ends with "skp". Maybe you are trying to do something like...

<result> {
for $fullPath in /vendorFile/fileList/file/fullPath
return
<item>
{$fullPath}
<matches> {
if (ends-with(lower-case($fullPath), "skp")) then
"yes"
else
"no"
} </matches>
</item>
} </result>

Postnext
David CostelloeSubject: Adding embedded functions
Author: David Costelloe
Date: 14 May 2008 02:14 PM
Hi,
Sorry, I am using Xpath query. I can only pass the query as:
/vendorFile/fileList/file/fullPath/text()[ends-with(., '.SKIP')]

I tried using your sample in the Stylus Xpath editor which failed with
Unreconized character '<'(0x3C)[err:XPST0003]

Is there any special formatting I need to do?

Thanks

Postnext
Minollo I.Subject: Adding embedded functions
Author: Minollo I.
Date: 14 May 2008 02:20 PM
Then the closest you can get is:

for $fullPath in /vendorFile/fileList/file/fullPath
return (
$fullPath,
if (ends-with(lower-case($fullPath), "skp")) then "yes" else "no"
)

That's XPath 2.0, which is what Stylus will run for you.
I don't see how to do the same in XPath 1.0

Postnext
David CostelloeSubject: Adding embedded functions
Author: David Costelloe
Date: 14 May 2008 02:40 PM
Great!
Worked like a charm.

The result being:
<xqr:xpath-query-result xmlns:xqr="http://www.stylusstudio.com/xpath-query-result">
<!-- Query Result: Element(s) -->
<fullPath>/Price/myfile1.doc</fullPath>
<!-- Query Result: Atomic Value(s):Type (http://www.w3.org/2001/XMLSchema:string) --> no
<fullPath>/Price/myfile2.skp</fullPath>
<!-- Query Result: Atomic Value(s):Type (http://www.w3.org/2001/XMLSchema:string) --> yes
</xqr:xpath-query-result>

Is it possible to return just the true and exclude the false?

I changed to: for $fullPath in /vendorFile/fileList/file/fullPath return ($fullPath,ends-with(lower-case($fullPath), "skp"))

The result returns both true and false for all the <fullPath>

<xqr:xpath-query-result xmlns:xqr="http://www.stylusstudio.com/xpath-query-result">
<!-- Query Result: Element(s) -->
<fullPath>/Price/myfile1.doc</fullPath>
<!-- Query Result: Atomic Value(s):Type (http://www.w3.org/2001/XMLSchema:boolean) --> false
<fullPath>/Price/myfile2.SKP</fullPath>
<!-- Query Result: Atomic Value(s):Type (http://www.w3.org/2001/XMLSchema:boolean) --> true
</xqr:xpath-query-result>

My apologies if I am asking the wrong questions.

Thanks

Postnext
Minollo I.Subject: Adding embedded functions
Author: Minollo I.
Date: 14 May 2008 02:45 PM
Do you want to exclude the non-matching ones from the list of returned values? Or you don't want to return "no" for the non-matching ones?

If you want the former, then you are going back to your original expression... if you want the latter, you can do:

for $fullPath in /vendorFile/fileList/file/fullPath
return (
$fullPath,
if (ends-with(lower-case($fullPath), "skp")) then "yes" else ()
)

Postnext
David CostelloeSubject: Adding embedded functions
Author: David Costelloe
Date: 14 May 2008 02:55 PM
Originally Posted: 14 May 2008 02:53 PM
Hi,

I would not like to return the non matching if possible and convert to lower-case to ensure I am able to pickup and upper-case if added by accident.

Thanks

Postnext
Minollo I.Subject: Adding embedded functions
Author: Minollo I.
Date: 14 May 2008 02:57 PM
Maybe I'm slower than usual today, but I'm not following you.
Can you provide an example?

Postnext
David CostelloeSubject: Adding embedded functions
Author: David Costelloe
Date: 14 May 2008 03:13 PM
Hi,
Nope not slow as I did not explain very well.

If I use:
/vendorFile/fileList/file/fullPath[ends-with(.,'skp')]

The return result is the matched file only and a boolean of true

Somehow I would like to have the check case:
This is wrong as i can't seem to place the lower-case in the right spot.

/vendorFile/fileList/file/fullPath[ends-with(lower-case(.,'skp'))]

Error of 1 argument is undefined. I will be using the for each sample that you provided with another query I'm working on :-)

Thanks

Postnext
Minollo I.Subject: Adding embedded functions
Author: Minollo I.
Date: 14 May 2008 03:18 PM
Depending on what you want to lower case (the match condition or the result), you'll do:

/vendorFile/fileList/file/fullPath[ends-with(lower-case(.),'skp')]

or

/vendorFile/fileList/file/fullPath[ends-with(.,'skp')]/lower-case(.)

Note that the first query returns a sequence of elements; the second one returns a sequence of strings.

Posttop
David CostelloeSubject: Adding embedded functions
Author: David Costelloe
Date: 14 May 2008 03:29 PM
Hi,
Thank You for your help. Works great.

Thanks again.

 
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.