XPath CheckBoxList

Uses an XPath expression to select nodes from the content tree to use as the checkbox options. The advantage of using XPath to define the nodes to use is that it allows a granular selection throughout the whole tree.

Can use $currentPage and also $parentPage within the XPath expression (including use within any XPath predicates). ($parentPage allows the expression to be evaluated when the current node is unpublished, and the XPath expression depends on finding nodes based on a current ancestor).

The property value stored can be a CSV string or an XML fragment of Node Ids or Node names.

Pre-value editor settings

Content editor

Example xml

<XPathCheckBoxList>
  <nodeId>1</nodeId>
  <nodeId>4</nodeId>
  <nodeId>5</nodeId>
</XPathCheckBoxList>

or

<
XPathCheckBoxList> <nodeName>Red</nodeName> <nodeName>Green</nodeName> <nodeName>Blue</nodeName> <XPathCheckBoxList>

uQuery

If node Ids are stored then the helper methods can also be used:

Node currentNode = uQuery.GetCurrentNode();

List<Node> colourNodes = uQuery.GetNodesByCsv(currentNode.GetProperty<string>("propertyAlias"));

or

List<Node> colourNodes = uQuery.GetNodesByXml(currentNode.GetProperty<string>("propertyAlias"));

 

Last edited Mar 2, 2011 at 9:57 AM by Hendy, version 9

Comments

JoshReid Jun 21, 2012 at 10:37 PM 
How can we use this with Contour?

When using as a Data Source in Contour it is not saving to a Page with property of same datatype (configured as XML + Node Ids).

It saves all values to the record, but only ever saves the first selected checkbox into the Page, not all values as expected and required...

Thoughts?

CDeCinko Sep 21, 2011 at 3:30 PM 
How do I sort via the sort order? Neither <xsl:sort select="$currentPage/advertisements/XPathCheckBoxList/sortOrder" data-type="number" order="ascending" /> nor <xsl:sort select="@sortOrder" data-type="number" order="ascending" /> seem to be working.

CDeCinko Jun 23, 2011 at 6:12 PM 
How do I get a count of nodes when using XML? I want to conditionally display some markup only if there is at least one node returned.

JohnCScott Apr 27, 2011 at 9:36 AM 
if you choose to store it as XML instead of CSV the XSLT is a tiny bit simpler
where "contentTags" is the name of the generic property you created with the XPathCheckBoxList data type

<xsl:for-each select="$currentPage/contentTags/XPathCheckBoxList/nodeId">
<xsl:variable name="node" select="umbraco.library:GetXmlNodeById(.)" />
<xsl:value-of select="$node/@nodeName"/><br/>
</xsl:for-each >

uniquelau Mar 14, 2011 at 2:04 PM 
The following is a XSLT snippet, for splitting the CSV ID values, and looping over them...

<xsl:variable name="tags" select="umbraco.library:Split($currentPage/contentTags, ',')" />

<!-- Loop over each tag -->
<xsl:for-each select="$tags/*" >
<!-- Grab XML for tag -->
<xsl:variable name="node" select="umbraco.library:GetXmlNodeById(.)" />
<!-- Access data on tag, in the same way you would use $currentPage -->
<xsl:value-of select="$node/@nodeName"/>
</xsl:for-each>

Laurie