Tech Team

July 6, 2009

XSLT Concatenating the output from nodes with comma seperation

Filed under: xslt — tpmccallum @ 2:22 am

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>

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.