I have a result set exported from MySQL as XML that looks, in general, like this:
Code:
<?xml version="1.0"?>
<resultset statement="select * from CAALBUMIMAGES where AlbumID = 9980121727059 order by ImageFileName ASC LIMIT 0, 1000"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<row>
<field name="AlbumID">9980121727059</field>
<field name="ImageID">9990246556401</field>
<field name="ImageFileName">First step</field>
<field name="ImageExtension">jpg</field>
<field name="Title" xsi:nil="true" />
<field name="ShortDescription"></field>
<field name="Description"></field>
<field name="AlbumCover">0</field>
</row>
<row>
<field name="AlbumID">9980121727059</field>
<field name="ImageID">9980246556401</field>
<field name="ImageFileName">Next step</field>
<field name="ImageExtension">jpg</field>
<field name="Title" xsi:nil="true" />
<field name="ShortDescription"></field>
<field name="Description"></field>
<field name="AlbumCover">0</field>
</row>
<row>
<field name="AlbumID">9980121727059</field>
<field name="ImageID">9970246556401</field>
<field name="ImageFileName">Finally</field>
<field name="ImageExtension">jpg</field>
<field name="Title" xsi:nil="true" />
<field name="ShortDescription"></field>
<field name="Description"></field>
<field name="AlbumCover">0</field>
</row>
</resultset>
I wrote the following XQuery to create an XML file formatted to use as input to FileZilla:
Code:
xquery version "1.0";
declare namespace xsl="http://www.w3.org/1999/XSL/Transform";
<FileZilla3>
<Queue>
<Server>
<Host>www.hostname.com</Host>
<Port>21</Port>
<Protocol>0</Protocol>
<Type>0</Type>
<User>username</User>
<Pass>password</Pass>
<Logontype>1</Logontype>
<TimezoneOffset>0</TimezoneOffset>
<PasvMode>MODE_DEFAULT</PasvMode>
<MaximumMultipleConnections>0</MaximumMultipleConnections>
<EncodingType>Auto</EncodingType>
<BypassProxy>0</BypassProxy>
<Name>site_name</Name>
{
for $i in fn:doc("test.xml"
)/resultset/row
where $i/field/@name="AlbumID" and contains(
$i/field[@name='AlbumID']/text(),"9980121727059"
)
return
<File>
<LocalFile>F:\Temp\{ fn:string($i/field[@name="ImageID"]) }.jpg</LocalFile>
<RemoteFile>{ fn:string($i/field[@name="ImageID"]) }.jpg</RemoteFile>
<RemotePath>1 0 11 public_html 9 community 14 CommunityAlbum</RemotePath>
<Download>1</Download>
<DataType>1</DataType>
</File>
}
</Server>
</Queue>
</FileZilla3>
The output looks like this (at least the bit that matters):
Code:
<File>
<LocalFile>C:\Temp\9930122064832.jpg</LocalFile>
<RemoteFile>9930122064832.jpg</RemoteFile>
<RemotePath>1 0 11 public_html 9 community 14 CommunityAlbum</RemotePath>
<Download>1</Download>
<DataType>1</DataType>
</File>
<File>
<LocalFile>C:\Temp\9940246556403.jpg</LocalFile>
<RemoteFile>9940246556403.jpg</RemoteFile>
<RemotePath>1 0 11 public_html 9 community 14 CommunityAlbum</RemotePath>
<Download>1</Download>
<DataType>1</DataType>
</File>
<File>
<LocalFile>C:\Temp\9950246556403.jpg</LocalFile>
<RemoteFile>9950246556403.jpg</RemoteFile>
<RemotePath>1 0 11 public_html 9 community 14 CommunityAlbum</RemotePath>
<Download>1</Download>
<DataType>1</DataType>
</File>
What I would like to do is change the output for the <LocalFile> element such that instead of using the <field name="ImageID"> value, it substitutes the value from an incrementing counter. That is, I'd like the output to look like this:
Code:
<File>
<LocalFile>C:\Temp\1.jpg</LocalFile>
<RemoteFile>9930122064832.jpg</RemoteFile>
<RemotePath>1 0 11 public_html 9 community 14 CommunityAlbum</RemotePath>
<Download>1</Download>
<DataType>1</DataType>
</File>
<File>
<LocalFile>C:\Temp\2.jpg</LocalFile>
<RemoteFile>9940246556403.jpg</RemoteFile>
<RemotePath>1 0 11 public_html 9 community 14 CommunityAlbum</RemotePath>
<Download>1</Download>
<DataType>1</DataType>
</File>
<File>
<LocalFile>C:\Temp\3.jpg</LocalFile>
<RemoteFile>9950246556403.jpg</RemoteFile>
<RemotePath>1 0 11 public_html 9 community 14 CommunityAlbum</RemotePath>
<Download>1</Download>
<DataType>1</DataType>
</File>
Is there a way to do that in my XQuery code?