hi all,
I am using nodetree as the dynamic source for my selection list. I had
two tips that I would like to share with you.
1. Removing the default -Choose- option:
Hippo has a built-in option to control it, but I don't think it is
documented. Here is how it works:
It's controlled by a param called "choose-item", by default it's
true. To remove the -Choose- option, you have the define your
business-logic.xml like this:
<rule for="/root/myselect">
<selectionsource src="mysource.xml" type="nodetree" dynamic="true"
choose-item="false"/>
</rule>
2. Display childnodes
From the documentation I got the impression that all childnodes will
be displayed like "parent > child", but apparently it doesn't. So I
modified this transformer:
<hippo-cms>/sites/hippo-cms/editing/cf2/cocoon-cform-xmleditor/transform
ers/nodetree2selectionlist.xsl
I extracted the logic that prints a node as a template, and applied
this template recursively to the child nodes. Since I was using
shootbox, where the selection list gets sorted alphabetically every time
an item is removed from the selected box, I prepand the entire parent
path to child nodes to preserve the parent/child order after sort. This
makes the options very long though - I am still trying to set width for
shootbox widget, but so far with no success. Anyone has a lead on that
please help me out! Thanks!
I attached my copy of the nodetree2selectionlist.xsl at the end the
email. Hopefully it's helpful to people using dynamic selection lists
like me.
Regards,
Jun
<hippo-cms>/sites/hippo-cms/editing/cf2/cocoon-cform-xmleditor/transform
ers/nodetree2selectionlist.xsl
----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2001-2007 Hippo (www.hippo.nl)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"
xmlns:i18n="http://apache.org/cocoon/i18n/2.1"
xmlns:hc="http://hippo.nl/cms/1.0"
version="1.0">
<xsl:param name="chooseitem" select="'false'"/>
<xsl:template match="nodes">
<fd:selection-list>
<xsl:if test="$chooseitem!='false'">
<fd:item value="">
<fd:label>
<i18n:text>cms.cforms-editor.general.choose-from-list</i18n:text>
</fd:label>
</fd:item>
</xsl:if>
<xsl:for-each select="node">
<xsl:call-template name="nodechild"/>
</xsl:for-each>
</fd:selection-list>
</xsl:template>
<xsl:template name="nodechild">
<xsl:param name="parent" select="''"/>
<xsl:variable name="value">
<xsl:choose>
<xsl:when test="@id"><xsl:value-of select="@id"/></xsl:when>
<xsl:otherwise><xsl:value-of
select="@value"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<fd:item value="{$value}">
<xsl:if test="count(@default)=1 and @default = 'true'">
<hc:list-default/>
</xsl:if>
<xsl:if test="@id != @value">
<fd:label><i18n:text><xsl:value-of
select="$parent"/><xsl:value-of select="@value"/></i18n:text></fd:label>
</xsl:if>
</fd:item>
<xsl:variable name="parent">
<xsl:value-of select="concat($parent,@value,'>')"/>
</xsl:variable>
<xsl:for-each select="node">
<xsl:call-template name="nodechild">
<xsl:with-param name="parent" select="$parent"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
********************************************
Hippocms-dev: Hippo CMS development public mailinglist
Searchable archives can be found at:
MarkMail: http://hippocms-dev.markmail.org
Nabble: http://www.nabble.com/Hippo-CMS-f26633.html