Return to doc.sitecore.com

Valid for Sitecore 5.3.1
3.  Checklist
Prev Next

The value of checklist field is stored in the database as pipe-separated list of IDs of selected items. There is no leading and trailing pipe.

The expression below:

<xsl:value-of select="sc:fld('My Checklist',.)"/>


would output something similar to this:

{B9F4A9B3-FAD2-4D79-9F97-6E66D1FF33C4}|{E473B7A4-6956-4319-B69E-147D91223E4A}


This means that item with ID {B9F4A9B3-FAD2-4D79-9F97-6E66D1FF33C4} and item with ID {E473B7A4-6956-4319-B69E-147D91223E4A} were checked in checkbox list in the Sitecore client.

 

 

What to do with the list of IDs is up to you. You may want to pass it for processing to some Extension Object. It is also possible to parse the string in XSLT code using combination of substring-before, substring-after functions and recursive templates. Here is an example that prints names of selected items:

<xsl:variable name="home" select="/*/item[@key='content']/item[@key='home']" />  

...

        
<xsl:template match="*" mode="main">
  
<xsl:variable name="ids" select="concat(sc:fld('My Checklist',.),'|')"/>
  
<xsl:call-template name="PrintNames">
    
<xsl:with-param name="ids" select="$ids"/>
  
</xsl:call-template>
</xsl:template>

<xsl:template name="PrintNames">
  
<xsl:param name="ids"/>
  
<xsl:if test="$ids">
    
<xsl:variable name="itm_id" select="substring-before($ids, '|')"/>
    
<xsl:if test="$itm_id">
      
<xsl:value-of select="$home/item[@id = $itm_id]/@name"/>
      
<br/>
      
<xsl:call-template name="PrintNames">
        
<xsl:with-param name="ids" select="substring-after($ids, '|')"/>
      
</xsl:call-template>
    
</xsl:if>
  
</xsl:if>
</xsl:template>

Sample Content Editor input: 

 

Corresponding output in the Preview mode:



Prev Next