Last month, I wrote about transforming InfoPath form files that contain ink picture controls into Word 2003 documents. That task involved getting the ink picture data and associated background image from the form file into WordML. This month, the task at hand was the transformation of form files with a variable number of images into WordML. This type of transformation is similar to the one regarding the ink picture, except that the number of images to be transformed at runtime is unknown.

As with the previous transformation, each image is stored as base64Binary in the form’s data source and can be output in a w:binData element within a w:pict element. The base64Binary data in the form’s data source can be found in the img element’s xd:inline attribute. The w:name attribute value of the w:binData in the WordML output, however, must be unique and match the value of the src attribute for the v:imagedata element. These attribute values require the format “wordml://<UNIQUEID>“. To achieve this format, I used xsl:attribute elements in my XSL file and output the src attribute of the input img elements as my unique IDs, as shown in the following template:

<xsl:template match="xhtml:img">
                <xsl:attribute name="w:name">wordml://<xsl:value-of select="@src"/></xsl:attribute>
                <xsl:value-of select="@xd:inline"/>
            <v:shape id=_x0000_i1025 type="#_x0000_t75">
                <xsl:attribute name="style"><xsl:value-of select="@style"/></xsl:attribute>
                    <xsl:attribute name="src">wordml://<xsl:value-of select="@src"/></xsl:attribute>

For further guidance on what the w:pict element should look like in the WordML output for different image formats, check out David Thielen’s article Completing the WordML Spec.