Subject: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
<ImagesNoLongerUsed>{
for $image in $allImages/root/image/column.0
where exists(($imagesInUse[string(.) = string($image)]))
return $image
}</ImagesNoLongerUsed>
Subject: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.
Subject: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
Subject: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.