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
Rick ScofieldSubject: Xquery key value lookup
Author: Rick Scofield
Date: 21 Feb 2013 05:23 PM
We periodically need to remove unused image files from our web server that are not being referenced anymore in the database. I have two xml files, InputFile1 is the database output of all the images currently being used. InputFile2 is the web server image file listing of all the images in a certain folder.

For all image names in InputFile1 look-up the image name in InputFile2, if he image name exists then next record, else output the image name to file for later removal.

I have done this using XSLT before using @key/@lookup like:
<xsl:variable name="Lookup" select="document('RproBod.xml')"/>
...
<xsl:variable name="upc" select="upc"/>
<xsl:variable name="rproqty">
<xsl:for-each select="$Lookup">
<xsl:value-of select="key('upcToqty', $upc)/rproqty"/>
</xsl:for-each>
</xsl:variable>

I'm trying to get this working using Xquery, is this possible?
Thanks for any help,
Rick

Postnext
Ivan PedruzziSubject: Xquery key value lookup
Author: Ivan Pedruzzi
Date: 21 Feb 2013 05:37 PM

Hi Rick,

Can you post here samples of the two input files?

Notice that using DataDirect XQuery, most likely you can query the database directly without the need to dump the data to an XML file.

Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
Rick ScofieldSubject: Xquery key value lookup
Author: Rick Scofield
Date: 21 Feb 2013 06:12 PM
Originally Posted: 21 Feb 2013 06:09 PM
Thanks Ivan,
Here are the two input files.
InputFile1 = attr.xml
InputFile2 = DIRAF21.dat

My database is MySQL


Unknownattr.xml
database file1

UnknownDIRAF21.dat
file system listing file2

Postnext
Ivan PedruzziSubject: Xquery key value lookup
Author: Ivan Pedruzzi
Date: 21 Feb 2013 09:27 PM
Have a look at the query at the bottom which runs really fast using Saxon

To learn how to access relational data directly using DataDirect XQuery, look at the video tutorial
http://www.stylusstudio.com/videos/ddxqdemo/datadirectxquery.html


Hope this helps
Ivan Pedruzzi
Stylus Studio Team


declare variable $allImages := doc("converter:CSV:root=root:row=image?DIRAF21.dat");
declare variable $imagesInUse := distinct-values(doc('attr.xml')/AttrOptn/*/Image);


<ImagesNoLongerUsed>{
for $image in $allImages/root/image/column.0
where exists(($imagesInUse[string(.) = string($image)]))
return $image
}</ImagesNoLongerUsed>

Postnext
Rick ScofieldSubject: Xquery key value lookup
Author: Rick Scofield
Date: 22 Feb 2013 01:47 PM
Hello Ivan,
Sorry to bug you again, however after review the output it's not what I expect. For example the provided sample code will output value "100074001_SW.jpg", But this value *is* contained in the xml file $imagesInUse, therefore is being used and should not be removed. I have played around with the syntax in the where clause with no luck.

Thanks for any more ideas,
Rick

Postnext
Rick ScofieldSubject: Xquery key value lookup
Author: Rick Scofield
Date: 22 Feb 2013 07:47 AM
Thank you Ivan,
I've been using XSLT for past 5 years and now beginning to see the power and usefulness of using Xquery. This is the reason I purchased Stylus Studio in 2005 and keep using it....this forum and the prompt expert advise you guys provide is invaluable! Keep up the great work!

Thank you again for the help, your ideas worked and now will look into tying into the database.
Rick

Postnext
Ivan PedruzziSubject: Xquery key value lookup
Author: Ivan Pedruzzi
Date: 22 Feb 2013 02:43 PM

Yep, try this


declare variable $allImages := doc("converter:CSV:root=root:row=image?DIRAF21.dat");
declare variable $imagesInUse := distinct-values(doc('attr.xml')/AttrOptn/*/Image);

<ImagesNoLongerUsed>{
for $image in $allImages/root/image/column.0
where not(exists(($imagesInUse[. = $image])))
return $image
}</ImagesNoLongerUsed>

Posttop
Rick ScofieldSubject: Xquery key value lookup
Author: Rick Scofield
Date: 22 Feb 2013 05:26 PM
Thank again Ivan,
That was the trick. I was using something like:
where exists(($imagesInUse[string(.) != string($image)]))
or
where (string($image) != $imagesInUse[string(.)])
which was not working for me.

Thanks, Rick

 
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-2016 All Rights Reserved.