XSLTForms: set attributes on output node? (<xf:output>)

23 Views Asked by At

The following output works (it is part of an <xforms:repeat), but is there a way I can dynamically set the value of attributes?

<xf:output value="concat(
instance('images')/@base_api,
resource[@href=../links/resource[@rel='image']/@href]/links/resource[@rel='thumbnail']/@href)" 
mediatype="image/*
width="64px" height="64px"
/>

So assuming I have 'width' and 'height' properties within my model - is there a way of setting the attributes from the model, rather than hard-coding to '64px' as I have here?

I also want to set the 'alt' attribute.

I'm using client-side XSLTForms, Version: 1.2.

2

There are 2 best solutions below

1
Alain Couthures On BEST ANSWER

AVT allows you to embed XPath expressions within an attribute value using {}. For example: width="{resource/image/size * 2}px"

0
monojohnny On

Based on the comment provided - I was able to do this using AVT - and instead of using <xf:output>, just use <img...> tags. This also allows you to ditch the 'concat' , and just place each AVT within the attribute.

Here's an example for 'title'.

<img
src="{instance('images')/@base_api}{resource[@href=../links/resource[@rel='image']/@href]/links/resource[@rel='thumbnail']/@href}"
title="{resource[@href=../links/resource[@rel='image']/@href]/image_sha1}"
/>

I guess this could be tidied-up using a bind in the model, and just referencing that instead of having all the XPath cluttering up the view.