chewDK
February 14, 2020, 9:03pm
1
Hey all,
I'm trying to finalise my print functionality for my Form Instances.
Everything works perfectly except that I'm unable to retrieve the photos to print.
I'm currently transforming the Form Instance XML file into HTML using XSLT.
I need to fetch the photos but so far having no luck as the name of the Form Instance isn't included in the XML file and so I can't insert the corresponding folder name/path into the HTML.
Currently I have
<img src="file:///storage/emulated/0/odk/instances/*/{$foto}"/>
Where $foto is the 123456.jpg value inserted into the XML when the Form Instance is saved.
Any ideas how can I find the value for * ?
(I was hoping * would just work as a wildcard, but no such luck )
Cheers!
chewDK
February 14, 2020, 9:32pm
2
Well I found a solution, but it's pretty horrible!
I had to do a load of character manipulation to derive the folder path from the start time in the XML file.
<xsl:variable name="instancefolderfirst19" select="substring(form_id/start/text(),1,19)" />
<xsl:variable name="instancefolderremoveT" select="translate($instancefolderfirst19,'T','_')" />
<xsl:variable name="instancefolderreplacecolon" select="translate($instancefolderremoveT,':','-')" />
<xsl:variable name="instancefolder" select="concat('form_instance_name',$instancefolderreplacecolon)" />
<xsl:variable name="foto1" select="form_id/datos_press/foto" />
<td><img src="file:///storage/emulated/0/odk/instances/{$instancefolder}/{$foto1}" height="150"/></td>
Ugggly!
But it works so I'm happy haha
1 Like
chewDK:
<xsl:variable name="instancefolderremoveT" select="translate($instancefolderfirst19,'T','_')" /> <xsl:variable name="instancefolderreplacecolon" select="translate($instancefolderremoveT,':','-')" />
FYI the XPath translate() function can do multiple char substitutions, so these can probably be simplified to
<xsl:variable name="instancefoldertranslate" select="translate($instancefolderfirst19,'T:','_-')" />
still uggly, but perhaps a bit less so...
2 Likes
chewDK
February 14, 2020, 9:53pm
4
Oh nice! Didn't realise that, thanks @Xiphware