You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Frank MW <mu...@gmx.de> on 2006/07/22 09:18:48 UTC
selection-list getting items from xml-file
Hi all,
I'm trying to get the values for a selection-list from an xml - file,
but there is not much documentation around and I haven't found a
fitting hint yet. That's what I tried rather intuitively:
<fd:field id="test" required="false">
<fd:datatype base="string"></fd:datatype>
<fd:label>Clause - Test</fd:label>
<fd:selection-list src="forms/auswahl.xml" value-path="option"
list-path="auswahl" dynamic="true"></fd:selection-list>
</fd:field>
with auswahl.xml:
<auswahl>
<option>nested clause</option>
<option>if-clause</option>
<option>adverbial clause</option>
</auswahl>
How do I have to do that? Or if there is documentation on it, could
you provide me with the link, since I couldn't find it. What I need
is not in here:
http://cocoon.apache.org/2.1/userdocs/widgetconcepts/selectionlists.html
since it just says:
<fd:datatype base="string"/>
<fd:selection-list src="cocoon:/mychoices.xml" dynamic="true"/>
But how do I specify the path in the xml-file?
Regards,
Frank
Re: selection-list getting items from xml-file
Posted by Simone Gianni <s....@thebug.it>.
Hi Frank,
the selection list can load their items from a file:
<fd:selection-list src="options.xml"/>
but it expect the file to follow a certain schema :
<fd:selection-list>
<fd:item value="a"/>
<fd:item value="b">
<fd:label>b has a label</fd:label>
</fd:item>
...
</fd:selection-list>
BUT, when cocoon reads a file (in cocoon forms, and in may other places,
basically everywhere) it does not simply opens the file and reads the
content. It uses an abstraction called Source.
A Source is a generic way of accessing something that can generate the
data you need, be it a file on the file system, a file in the web
application context, a resource (again a file) placed in a jar file, an
HTTP or FTP site, or many other things.
The way it works is simply placing the correct protocol in front of the
source specification, for example :
<fd:selection-list src="options.xml"/> // The file:/ protocol is implied
<fd:selection-list
src="http://ups.com/services/expedition-options.xml"/> // Another
company could offer selection lists for their services
<fd:selection-list src="ftp://user:pass@host.com/home/user/options.xml"/>
etc.. etc..
A very important part of it is that cocoon can act as a source itself,
and that's the solution to your problem : you can write a pipe and then
call it from the selection list, for example :
<map:match="myoptions.xml">
<map:generate src="auswahl.xml"/>
<map:transform src="auswahl-to-selectionlist.xsl"/>
<map:serialize type="xml"/>
</map:match>
and then in the definition
<fd:selection-list src="cocoon:/myoptions.xml"/>
The XSL could be as simple as :
<xsl:template match="auswahl">
<fd:selection-list>
<xsl:apply-templates/>
</fd:selection-list>
</xsl:template>
<xsl:template match="option">
<fd:item value="{.}"/>
</xsl:template>
Hope this helps,
Simone
Frank MW wrote:
> Hi all,
>
> I'm trying to get the values for a selection-list from an xml - file,
> but there is not much documentation around and I haven't found a
> fitting hint yet. That's what I tried rather intuitively:
>
> <fd:field id="test" required="false">
> <fd:datatype base="string"></fd:datatype>
> <fd:label>Clause - Test</fd:label>
> <fd:selection-list src="forms/auswahl.xml" value-path="option"
> list-path="auswahl" dynamic="true"></fd:selection-list>
> </fd:field>
>
> with auswahl.xml:
>
> <auswahl>
> <option>nested clause</option>
> <option>if-clause</option>
> <option>adverbial clause</option>
> </auswahl>
>
>
> How do I have to do that? Or if there is documentation on it, could
> you provide me with the link, since I couldn't find it. What I need is
> not in here:
> http://cocoon.apache.org/2.1/userdocs/widgetconcepts/selectionlists.html
>
> since it just says:
>
> <fd:datatype base="string"/>
> <fd:selection-list src="cocoon:/mychoices.xml" dynamic="true"/>
>
> But how do I specify the path in the xml-file?
>
>
> Regards,
> Frank
--
Simone Gianni
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: selection-list getting items from xml-file
Posted by Simone Gianni <s....@thebug.it>.
Ups, missed this answer before writing mine :)
Simone
Jason Johnston wrote:
> Frank MW wrote:
>
>> Hi all,
>>
>> I'm trying to get the values for a selection-list from an xml - file,
>> but there is not much documentation around and I haven't found a
>> fitting hint yet. That's what I tried rather intuitively:
>>
>> <fd:field id="test" required="false">
>> <fd:datatype base="string"></fd:datatype>
>> <fd:label>Clause - Test</fd:label>
>> <fd:selection-list src="forms/auswahl.xml" value-path="option"
>> list-path="auswahl" dynamic="true"></fd:selection-list>
>> </fd:field>
>>
>> with auswahl.xml:
>>
>> <auswahl>
>> <option>nested clause</option>
>> <option>if-clause</option>
>> <option>adverbial clause</option>
>> </auswahl>
>>
>>
>> How do I have to do that? Or if there is documentation on it, could
>> you provide me with the link, since I couldn't find it. What I need
>> is not in here:
>> http://cocoon.apache.org/2.1/userdocs/widgetconcepts/selectionlists.html
>>
>> since it just says:
>>
>> <fd:datatype base="string"/>
>> <fd:selection-list src="cocoon:/mychoices.xml" dynamic="true"/>
>>
>> But how do I specify the path in the xml-file?
>
>
> The docs say that the format of the XML file has to match that of the
> normal inline fd:selection-list declaration:
>
> <fd:selection-list>
> <fd:item value="value1">
> <fd:label>Label1</fd:label>
> </fd:item>
> <fd:item value="value2" />
> </fd:selection-list>
>
> The value-path and list-path attributes only apply to the flow-jxpath
> implementation, not when you're referencing an external XML file.
>
> To get your file into that format you can use a cocoon:/ URI to
> reference a pipeline which transforms it into the correct format via
> XSLT.
>
> === Form definition: ===
> <fd:selection-list src="cocoon:/mychoices-selection-list.xml"
> dynamic="true" />
>
> === Sitemap: ===
> <map:match pattern="mychoices-selection-list.xml">
> <map:generate src="mychoices.xml" />
> <map:transform src="mychoices-to-selection-list.xsl" />
> <map:serialize type="xml" />
> </map:match>
>
> === mychoices-to-selection-list.xsl: ===
> <xsl:stylesheet ...>
> <xsl:template match="auswahl">
> <fd:selection-list>
> <xsl:apply-templates />
> </fd:selection-list>
> </xsl:template>
>
> <xsl:template match="option">
> <fd:item value="{.}" />
> </xsl:template>
> </xsl:stylesheet>
>
>
>
>
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: selection-list getting items from xml-file
Posted by Jason Johnston <co...@lojjic.net>.
Frank MW wrote:
> Hi all,
>
> I'm trying to get the values for a selection-list from an xml - file,
> but there is not much documentation around and I haven't found a fitting
> hint yet. That's what I tried rather intuitively:
>
> <fd:field id="test" required="false">
> <fd:datatype base="string"></fd:datatype>
> <fd:label>Clause - Test</fd:label>
> <fd:selection-list src="forms/auswahl.xml" value-path="option"
> list-path="auswahl" dynamic="true"></fd:selection-list>
> </fd:field>
>
> with auswahl.xml:
>
> <auswahl>
> <option>nested clause</option>
> <option>if-clause</option>
> <option>adverbial clause</option>
> </auswahl>
>
>
> How do I have to do that? Or if there is documentation on it, could you
> provide me with the link, since I couldn't find it. What I need is not
> in here:
> http://cocoon.apache.org/2.1/userdocs/widgetconcepts/selectionlists.html
>
> since it just says:
>
> <fd:datatype base="string"/>
> <fd:selection-list src="cocoon:/mychoices.xml" dynamic="true"/>
>
> But how do I specify the path in the xml-file?
The docs say that the format of the XML file has to match that of the
normal inline fd:selection-list declaration:
<fd:selection-list>
<fd:item value="value1">
<fd:label>Label1</fd:label>
</fd:item>
<fd:item value="value2" />
</fd:selection-list>
The value-path and list-path attributes only apply to the flow-jxpath
implementation, not when you're referencing an external XML file.
To get your file into that format you can use a cocoon:/ URI to
reference a pipeline which transforms it into the correct format via XSLT.
=== Form definition: ===
<fd:selection-list src="cocoon:/mychoices-selection-list.xml"
dynamic="true" />
=== Sitemap: ===
<map:match pattern="mychoices-selection-list.xml">
<map:generate src="mychoices.xml" />
<map:transform src="mychoices-to-selection-list.xsl" />
<map:serialize type="xml" />
</map:match>
=== mychoices-to-selection-list.xsl: ===
<xsl:stylesheet ...>
<xsl:template match="auswahl">
<fd:selection-list>
<xsl:apply-templates />
</fd:selection-list>
</xsl:template>
<xsl:template match="option">
<fd:item value="{.}" />
</xsl:template>
</xsl:stylesheet>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: selection-list getting items from xml-file
Posted by 32...@gmail.com.
Hi Frank,
I don't have a real solution to your problem, but you can have a look at the
AJAX carselector sample in samples/blocks/forms. That one gets its selection
list from a xml file as well. Maybe that helps you....
Marco
2006/7/22, Frank MW <mu...@gmx.de>:
>
> Hi all,
> I'm trying to get the values for a selection-list from an xml - file, but
> there is not much documentation around and I haven't found a fitting hint
> yet. That's what I tried rather intuitively:
>
> <fd:field id="test" required="false">
> <fd:datatype base="string"></fd:datatype>
> <fd:label>Clause - Test</fd:label>
> <fd:selection-list src="forms/auswahl.xml" value-path="option"
> list-path="auswahl" dynamic="true"></fd:selection-list>
> </fd:field>
>
> with auswahl.xml:
>
> <auswahl>
> <option>nested clause</option>
> <option>if-clause</option>
> <option>adverbial clause</option>
> </auswahl>
>
>
> How do I have to do that? Or if there is documentation on it, could you
> provide me with the link, since I couldn't find it. What I need is not in
> here:
> http://cocoon.apache.org/2.1/userdocs/widgetconcepts/selectionlists.html
>
> since it just says:
>
> <fd:datatype base="string"/>
> <fd:selection-list src="cocoon:/mychoices.xml" dynamic="true"/>
>
> But how do I specify the path in the xml-file?
>
>
> Regards,
> Frank
>