Testing for a character and deleting it using xslt

This example is taken from an xslt document that was used to create Marc xml, so there is Marc metadata in here that is irrelevant to the xslt syntax.

<xsl:template match=”marc:datafield[@tag=’245′]”>
<dc:title>
<xsl:variable name=”titleString”>
<xsl:value-of select=”child::marc:subfield[@code=’b’]”/>
</xsl:variable>
<xsl:variable name=”lengthString” select=”string-length($titleString)”/>
<xsl:variable name=”lastChar” select=”substring($titleString,$lengthString – 1)”/>
<xsl:choose>
<xsl:when test=”$lastChar = ‘ /’ “>
<xsl:variable name=”titleStringMod” select=”substring($titleString, 1, $lengthString – 1)”/>
<xsl:value-of select=”child::marc:subfield[@code=’a’]”/>: <xsl:value-of select=”$titleStringMod”/>
</xsl:when>
<xsl:otherwise><xsl:value-of select=”child::marc:subfield[@code=’a’]”/>: <xsl:value-of select=”$titleString”/>
</xsl:otherwise>
</xsl:choose>
</dc:title>
<xsl:variable name=”string”>
<xsl:value-of select=”child::marc:subfield[@code=’h’]”/>
</xsl:variable>
<xsl:variable name=”start”>
<xsl:value-of select=”substring-after($string,'[‘)”/>
</xsl:variable>
<dc:format>
<xsl:value-of select=”substring-before($start,’]’)”/>
</dc:format>
</xsl:template>

Advertisements

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