Discussion:
dynamic include of SVG image
Dan McCreary
2014-09-26 14:24:02 UTC
Permalink
Hi folks,

I have a form that the user is uploading a SVG image and I would like to
show a preview of it after the file has been selected.

I have seen that the <xf:include src=""> element allows us to place the SVG
image in the form like this:

<xf:include src="images/blue-circle.svg"/>

Here is the example on github:

https://github.com/AlainCouthures/xsltforms/blob/master/testsuite/samples/flags.xhtml

Is there a way to dynamically load the image? I tried:

<xf:include src="images/{$filename}"/>

but that did not work.

Perhaps some combination of an XForms on-change event and xf:load?

Thanks! - Dan
--
Dan McCreary
http://danmccreary.com
Co-author: Making Sense of NoSQL <http://manning.com/mccreary>
office: (952) 931-9198
cell: (612) 986-1552
skype: dmccreary47
Alain Couthures
2014-09-26 16:03:12 UTC
Permalink
Hi Dan,

xf:include/@src is interpreted at load time, like some preprocessor
instruction, so it is not possible to use it for this use case.

Is xf:upload used to upload the SVG image? If so, I have just
experimented adding support for "string" type!

My test case is:

<html xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>SVG Upload+Preview</title>
<xforms:model>
<xforms:instance xmlns="">
<data>
<content/>
</data>
</xforms:instance>
</xforms:model>
</head>
<body>
<h1>Uploads and types</h1>
<p>
<xforms:upload ref="content" incremental="true">
<xforms:label>Upload: </xforms:label>
</xforms:upload>
<br/>
<xforms:output value="content" mediatype="application/xhtml+xml">
<xforms:label>Content:&#160;</xforms:label>
</xforms:output>
</p>
</body>
</html>

This is not committed yet. Is it what you are looking for?

--Alain
Post by Dan McCreary
Hi folks,
I have a form that the user is uploading a SVG image and I would like
to show a preview of it after the file has been selected.
I have seen that the <xf:include src=""> element allows us to place
<xf:include src="images/blue-circle.svg"/>
https://github.com/AlainCouthures/xsltforms/blob/master/testsuite/samples/flags.xhtml
<xf:include src="images/{$filename}"/>
but that did not work.
Perhaps some combination of an XForms on-change event and xf:load?
Thanks! - Dan
--
Dan McCreary
http://danmccreary.com
Co-author: Making Sense of NoSQL <http://manning.com/mccreary>
office: (952) 931-9198
cell: (612) 986-1552
skype: dmccreary47
Loading...