cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simone Gianni <s.gia...@thebug.it>
Subject Re: selection-list getting items from xml-file
Date Sat, 22 Jul 2006 16:13:04 GMT
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


Mime
View raw message