Xslt format for image import


(Gjboyd7) #1

What is the correct xslt format for image import scripting.

Here is what I have currently - which does not create the image assets and a PHP notice is thrown - Undefined index: tmp_name

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/photos">
    <squizfeed>
      <xsl:apply-templates select="photo"/>
    </squizfeed>
  </xsl:template>

  <xsl:template match="photo">
    <feeddata action="takeover">
      <newhomes>
        <newhome>
          <searchhomes>
            <searchhome assetid="default" autocreate="true">
              <assetset>
                <asset assettype="Folder" autocreate="true" status="live">
                  <assetattribute name="name"><xsl:value-of select="set" /> - <xsl:value-of select="set_id" /></assetattribute>
                </asset>
              </assetset>
            </searchhome>
          </searchhomes>
        </newhome>
      </newhomes>
      <assetset>
        <asset assettype="File" typecode="Image" linktype="type-1" status="live" file_path="/var/www/html/flickr_feed/images/31667502043_aba2ee5e06_b.jpg">
          <assetattribute name="assetid" primarykey="true"><xsl:value-of select="squiz_id" /></assetattribute>
          <assetattribute name="name"><xsl:value-of select="id" /></assetattribute>
          <assetattribute name="alt"><xsl:value-of select="title" /></assetattribute>
          <assetattribute name="caption"><xsl:value-of select="title" /></assetattribute>
        </asset>
      </assetset>
    </feeddata>
  </xsl:template>
</xsl:stylesheet>

(Bart Banda) #2

Not sure, maybe try and export an image using the Export to XML tool and look at the formatting of that XML and replicate from there?


(Nic) #3

Here’s an example of an image asset being created and some properties being set, some are not mandatory:
<?xml version=β€œ1.0” encoding=β€œutf-8”?>
<actions>
<action>
<action_id>create_image_1</action_id>
<action_type>create_file_asset</action_type>
<file_path>export/Image/Blackspot1.jpg</file_path>
<type_code>image</type_code>
<link_type>1</link_type>
<parentid>277981</parentid>
<value></value>
<is_dependant>0</is_dependant>
<is_exclusive>0</is_exclusive>
</action>
<action>
<action_id>set_status_1_under_construction</action_id>
<action_type>set_status</action_type>
<asset>[[output://create_image_1.assetid]]</asset>
<status>2</status>
</action>
<action>
<action_id>set_standard_asset_date_1_created</action_id>
<action_type>set_standard_asset_date</action_type>
<asset>[[output://create_image_1.assetid]]</asset>
<date_field>created</date_field>
<when_type>explicit_exact</when_type>
<when><![CDATA[2017-02-27 --:–:--]]></when>
<offset_used>0</offset_used>
</action>
<action>
<action_id>set_standard_asset_date_1_published</action_id>
<action_type>set_standard_asset_date</action_type>
<asset>[[output://create_image_1.assetid]]</asset>
<date_field>published</date_field>
<when_type>explicit_exact</when_type>
<when><![CDATA[2017-02-27 --:–:--]]></when>
<offset_used>0</offset_used>
</action>
<action>
<action_id>set_standard_asset_date_1_updated</action_id>
<action_type>set_standard_asset_date</action_type>
<asset>[[output://create_image_1.assetid]]</asset>
<date_field>updated</date_field>
<when_type>explicit_exact</when_type>
<when><![CDATA[2017-02-27 --:–:--]]></when>
<offset_used>0</offset_used>
</action>
<action>
<action_id>add_image_1_path</action_id>
<action_type>add_web_path</action_type>
<asset>[[output://create_image_1.assetid]]</asset>
<path>Blackspot1.jpg</path>
</action>
<action>
<action_id>set_image_1_metadata_schema_11111</action_id>
<action_type>set_metadata_schema</action_type>
<asset>[[output://create_image_1.assetid]]</asset>
<schemaid>11111</schemaid>
</action>
<action>
<action_id>set_permission_1_read_242741</action_id>
<action_type>set_permission</action_type>
<asset>[[output://create_image_1.assetid]]</asset>
<permission>1</permission>
<granted>1</granted>
<userid>242741</userid>
</action>
<action>
<action_id>set_permission_1_write_222916</action_id>
<action_type>set_permission</action_type>
<asset>[[output://create_image_1.assetid]]</asset>
<permission>2</permission>
<granted>1</granted>
<userid>222916</userid>
</action>
<action>
<action_id>set_permission_1_admin_222917</action_id>
<action_type>set_permission</action_type>
<asset>[[output://create_image_1.assetid]]</asset>
<permission>3</permission>
<granted>1</granted>
<userid>222917</userid>
</action>
<action>
<action_id>set_image_1_name</action_id>
<action_type>set_attribute_value</action_type>
<asset>[[output://create_image_1.assetid]]</asset>
<attribute>name</attribute>
<value><![CDATA[Blackspot1.jpg]]></value>
</action>
<action>
<action_id>set_image_1_caption</action_id>
<action_type>set_attribute_value</action_type>
<asset>[[output://create_image_1.assetid]]</asset>
<attribute>caption</attribute>
<value><![CDATA[Ross]]></value>
</action>
</actions>


(Gjboyd7) #4

Thanks for that - I used this xslt to translate our image xml feed, along with the Matrix Feed Asset to create the image assets.

The uri attribute is very important.

  <assetset>
    <asset assettype="Image" linktype="type-2" status="live">
      <xsl:attribute name="uri">
        <xsl:value-of select="file_path" />
      </xsl:attribute>
      <assetattribute name="assetid" primarykey="true"><xsl:value-of select="squiz_id" /></assetattribute>
      <assetattribute name="alt"><xsl:value-of select="title" /></assetattribute>
    </asset>
  </assetset>