Concatenating xml nodes with comma separation using xslt.

 

Check to see if nodes are blank or not

<xsl:variable name=”volume” select=”../volume[. !=”]”/> <xsl:variable name=”number” select=”../number[. !=”]”/> <xsl:variable name=”pages” select=”../pages[. !=”]”/>

[ ] brackets mean “when”

!=” means is not equal to nothing (is not null)

eg variable name=”pages” select=”../pages when .(current node) Is not null

The following code concatenates the nodes depending on whether or not they exist and places some intro text before and a comma after each one providing there is another coming after it.

<xsl:if test=”$volume or $number or $pages“> <xsl:if test=”$volume“>Vol. <xsl:value-of select=”$volume“/></xsl:if> <xsl:if test=”$number or $pages“>, </xsl:if> <xsl:if test=”$number“>no. <xsl:value-of select=”$number“/> </xsl:if><xsl:if test=”$pages“>, </xsl:if> <xsl:if test=”$pages“><xsl:value-of select=”$pages“/></xsl:if> </xsl:if></marc:subfield>

 

 

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