In this step you will add the instructions that assign the values of the XSL variables to the GN4 attributes.

At this stage you need to know the structure of the GN4 schema, and which attributes are available for the GN4 object you are creating from a wire story.

In this example, it's the story object, and we're going to use its attributes: folderRef, sourceRef, and rights.

If you are unsure about the available attributes, review the appropriate schema and find out which attributes are available.

Assign a variable to an attribute (no testing)

You can assign the variable $folderPath to the attribute folderRef with this code:

 <folderRef>

   <keyVal>

     <xsl:value-of select="$folderPath"/>

   </keyVal>

 </folderRef>

Assign a variable to an attribute (with testing)

Before assigning a variable to the attribute, you may want to test if it's suitable, e.g., in the below example, we're testing first if the variable $sourceName is of the string type, and only if so, we assign its value to the sourceRef attribute.

 <xsl:if test="string($sourceName)">

   <sourceRef>

     <keyVal>

       <xsl:value-of select="$sourceName"/>

     </keyVal>

   </sourceRef>

 </xsl:if>

Use internal functions to transform the variable content

You may want to transform the variable content before assigning it to the attribute, e.g., in the below example we extract from the $srcPath variable only the file name (by means of the function fn:pathFileName) and then we assign its value to the sourceFileName attribute.

 <sourceFileName>

   <xsl:value-of select="fn:pathFileName($srcPath)"/>

 </sourceFileName>

Entire code of this step

<?xml version="1.0" encoding="utf-8"?>

<!--

 Simplified XSLT used to import AFP NewsML wires into the system

-->

<story name="{fn:createGuid()}" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 

 <xsl:variable name="folderPath" select="$pars/*/add[@key='folderPath']/@value" />

 <xsl:variable name="sourceName" select="$pars/*/add[@key='sourceName']/@value" />

 <xsl:variable name="copyrightName" select="$pars/*/add[@key='copyrightName']/@value" />

 <xsl:variable name="srcPath" select="$pars/*/add[@key='srcPath']/@value" />

 

  <folderRef>

    <keyVal>

      <xsl:value-of select="$folderPath"/>

    </keyVal>

  </folderRef>

 

  <xsl:if test="string($sourceName)">

    <sourceRef>

      <keyVal>

        <xsl:value-of select="$sourceName"/>

      </keyVal>

    </sourceRef>

  </xsl:if>

 

  <xsl:if test="string($copyrightName)">

    <rights>

      <ref>

        <keyVal>

          <xsl:value-of select="$copyrightName"/>

        </keyVal>

      </ref>

    </rights>

  </xsl:if>

 

  <sourceFileName>

    <xsl:value-of select="fn:pathFileName($srcPath)"/>

  </sourceFileName>

 

</story>

Note

At this stage, the code is still incomplete and will still create a story with an automatic name and some attributes.