How to declare a variable in xslt and assign it a value based on conditions

<xsl:template match=”itemType”>
<datafield tag=”655″ ind1=” ” ind2=”7″>
<subfield code=”a”>
<xsl:variable name=”resourceType”>
<xsl:choose>
<xsl:when test=”contains(.,’Full’)”>
<xsl:value-of select=”substring(.,5)”/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select=”.”/>
</xsl:otherwise>
</xsl:choose>

</xsl:variable>

In this code the xsl:when test refers to the contents of the marc datafield tag 655 subfield code a, as this is the node that the style sheet is currently positioned on.  If the contents of this node contains the word “Full” then the xsl:value-of select assigns the value of “.” to resourceType from the 5th character onwards. If the contents of this node does not contain the word full then the second  xsl:value-of select assigns the value of “.” to resourceType.

Advertisements

One thought on “How to declare a variable in xslt and assign it a value based on conditions

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s