25 October 2005

S4 vs. S5: multiselection

in S4, a multiselection field, when queried, returned a string with concatenated GUIDs, separated by '|', and _terminated_ with '|'

in S5, the final '|' has gone with the side effect that a loop processing the GUIDs will ignore the last item in the case of a transformation as follows:


<xsl:template match="*" mode="main">
<xsl:variable name="ids" select="sc:fld('Trademark',.)"/>
<div class="trademarks">
<xsl:call-template name="PrintText">
<xsl:with-param name="ids" select="$ids"/>
</xsl:call-template>
</div>
</xsl:template>

<xsl:template name="PrintText">
<xsl:param name="ids"/>
<xsl:if test="$ids">
<xsl:variable name="itm_id" select="substring-before($ids, '|')"/>
<xsl:if test="$itm_id">
<xsl:variable name="itm" select="sc:item($itm_id,.)"/>
<xsl:value-of select="sc:fld('text', $itm)"/> 
</xsl:if>
<xsl:call-template name="PrintText">
<xsl:with-param name="ids" select="substring-after($ids, '|')"/>
</xsl:call-template>
</xsl:if>
</xsl:template>



the (pretty common) code above will fail for S5. The workaround is:

<xsl:template match="*" mode="main">
<div id="leftcol">
<xsl:call-template name="PrintSideDocument">
<xsl:with-param name="ids" select="sc:fld('leftsidedocuments',.)" />
</xsl:call-template>
</div>
</xsl:template>

<xsl:template name="PrintSideDocument">
<xsl:param name="ids"/>

<xsl:if test="$ids">
<xsl:variable name="itm_id" select="substring-before($ids, '|')"/>
<xsl:variable name="locID">
<xsl:choose>
<xsl:when test="$itm_id">
<xsl:value-of select="$itm_id"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$ids"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:variable name="itm" select="sc:item($locID,.)"/>
<xsl:if test="$itm">
<h3><xsl:value-of select="sc:fld('title', $itm)"/></h3>
<xsl:value-of disable-output-escaping="yes" select="sc:fld('teaser',$itm)"/>
<xsl:if test="$itm_id">
<hr />
</xsl:if>
</xsl:if>

<xsl:call-template name="PrintSideDocument">
<xsl:with-param name="ids" select="substring-after($ids, '|')" />
</xsl:call-template>
</xsl:if>
</xsl:template>

1 comment:

Jukka-Pekka Keisala said...

Damn, it will be hell to update someday all my renderings to SC5 compliant.