You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Stephanie Zohner <st...@gmx.at> on 2004/05/12 10:31:20 UTC
Conditional replace / reinsert with SourceWritingTransformer
Hi specialists in SourceWritingTransformer usage ;-),
Here is my problem:
I want to replace and reinsert certain elements in an xml-filem if they have
set an attribute to a certain value:
For example:
My xml file looks like this
<page>
<a>
<b flag="true">1</b>
<b flag="false">2</b>
<b flag="true">3</b>
</a>
<deleted-a>
</deleted-a>
</page>
... and I want to transform it to this:
<page>
<a>
<b flag="false">2</b>
</a>
<deleted-b>
<b flag="true">1</b>
<b flag="true">3</b>
</deleted-b>
</page>
So only those "b" elements that have their attribute "flag" set to "true"
should be replaced and reinserted. How can I do this?
I tried:
<source:insert creatte="true">
<source:source>PathToMyFile.xml</source:source>
<source:path>/page/a</source:path>
<source:replace>b[@flag='true']</source:replace>
<source:fragment/>
<source:reinsert>/page/deleted-b</source:reinsert>
</source:insert>
In this case the "b" elements wanted aer replaced but only the values(!) of
the replaced elements are reinserted under <deleted-b> not the whole nodes.
So it looks like this ;-(
<page>
<a>
<b flag="false">2</b>
</a>
<deleted-b>13</b>
</deleted-b>
</page>
When I try differently, with:
<source:insert creatte="true">
<source:source>PathToMyFile.xml</source:source>
<source:path>/page</source:path>
<source:replace>a/b[@flag='true']</source:replace>
<source:fragment/>
<source:reinsert>/page/deleted-b</source:reinsert>
</source:insert>
I get the following (unexpected) output:
<page>
<deleted-b>
<b flag="true">1</b>
<b flag="false">2</b>
<b flag="true">3</b>
</deleted-b>
</page>
Element <a> and all! its <b> elements (ignoring the condition
[@flag="true"]) and all <b> elements (not only the values) are reinserted
under <deleted-b>.
Maybe the solution is close, but I can't see it. Can somebody bring light
into the darkness. How do I have to write the insert-directive. Or how can I
force the Transformer not only to reinsert the values but the whole node?
Thanks very much in advance,
Stephanie
--
NEU : GMX Internet.FreeDSL
Ab sofort DSL-Tarif ohne Grundgeb�hr: http://www.gmx.net/dsl
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Is it posibile to send parameters into form definition.
Posted by Bruno Dumon <br...@outerthought.org>.
On Fri, 2004-05-14 at 17:51, Bartosz Zgodzinski wrote:
> This is mine form definition file:
>
> <fd:form
> xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"
> xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
>
>
> <fd:repeater id="name" initial-size="{$my_var}">
> <fd:label>repeater</fd:label>
> <fd:widgets>
> <fd:field id="nazw1" >
> <fd:label>name</fd:label>
> <fd:datatype base="string"/>
> </fd:field>
> <fd:field id="nazw2" required="true">
> <fd:label>Nazwa:</fd:label>
> <fd:datatype base="string"/>
> </fd:field>
> </fd:widgets>
> </fd:repeater>
>
> {....}
> </fd:form>
>
> And now I want to send a variable from java script:
> var form = new
> Form("forms/my_form_definition_file.xml",{"my_var":my_var}); <--this
> doesn't work
> form.showForm("forms/t_nowyTyp.xml",{"my_var":my_var}); <-- when I
> send my_var to form template it works
>
This is not possible.
Just add the required number of rows to the repeater yourself by calling
addRow.
--
Bruno Dumon http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org bruno@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Is it posibile to send parameters into form definition.
Posted by Bartosz Zgodzinski <ba...@poczta.onet.pl>.
This is mine form definition file:
<fd:form
xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"
xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
<fd:repeater id="name" initial-size="{$my_var}">
<fd:label>repeater</fd:label>
<fd:widgets>
<fd:field id="nazw1" >
<fd:label>name</fd:label>
<fd:datatype base="string"/>
</fd:field>
<fd:field id="nazw2" required="true">
<fd:label>Nazwa:</fd:label>
<fd:datatype base="string"/>
</fd:field>
</fd:widgets>
</fd:repeater>
{....}
</fd:form>
And now I want to send a variable from java script:
var form = new Form("forms/my_form_definition_file.xml",{"my_var":my_var}); <--this doesn't work
form.showForm("forms/t_nowyTyp.xml",{"my_var":my_var}); <-- when I send my_var to form template it works
Bartosz Zgodzinski
Re: Conditional replace / reinsert with SourceWritingTransformer
Posted by la...@marinepower.com.
Hi ,
I think that you can easily do that with a simple XSL Transformer and not
a SourceWritingTransformer
Generate your XML
Pass it to XSL transformer (in your XSL you will do some <xsl:if
test="b/@flag='true'"> ... )
Serialize it
Hope it could help
Laurent
"Stephanie Zohner" <st...@gmx.at>
12/05/2004 10:31
Please respond to users
To: users@cocoon.apache.org
cc:
Subject: Conditional replace / reinsert with
SourceWritingTransformer
Hi specialists in SourceWritingTransformer usage ;-),
Here is my problem:
I want to replace and reinsert certain elements in an xml-filem if they
have
set an attribute to a certain value:
For example:
My xml file looks like this
<page>
<a>
<b flag="true">1</b>
<b flag="false">2</b>
<b flag="true">3</b>
</a>
<deleted-a>
</deleted-a>
</page>
... and I want to transform it to this:
<page>
<a>
<b flag="false">2</b>
</a>
<deleted-b>
<b flag="true">1</b>
<b flag="true">3</b>
</deleted-b>
</page>
So only those "b" elements that have their attribute "flag" set to "true"
should be replaced and reinserted. How can I do this?
I tried:
<source:insert creatte="true">
<source:source>PathToMyFile.xml</source:source>
<source:path>/page/a</source:path>
<source:replace>b[@flag='true']</source:replace>
<source:fragment/>
<source:reinsert>/page/deleted-b</source:reinsert>
</source:insert>
In this case the "b" elements wanted aer replaced but only the values(!)
of
the replaced elements are reinserted under <deleted-b> not the whole
nodes.
So it looks like this ;-(
<page>
<a>
<b flag="false">2</b>
</a>
<deleted-b>13</b>
</deleted-b>
</page>
When I try differently, with:
<source:insert creatte="true">
<source:source>PathToMyFile.xml</source:source>
<source:path>/page</source:path>
<source:replace>a/b[@flag='true']</source:replace>
<source:fragment/>
<source:reinsert>/page/deleted-b</source:reinsert>
</source:insert>
I get the following (unexpected) output:
<page>
<deleted-b>
<b flag="true">1</b>
<b flag="false">2</b>
<b flag="true">3</b>
</deleted-b>
</page>
Element <a> and all! its <b> elements (ignoring the condition
[@flag="true"]) and all <b> elements (not only the values) are reinserted
under <deleted-b>.
Maybe the solution is close, but I can't see it. Can somebody bring light
into the darkness. How do I have to write the insert-directive. Or how can
I
force the Transformer not only to reinsert the values but the whole node?
Thanks very much in advance,
Stephanie
--
NEU : GMX Internet.FreeDSL
Ab sofort DSL-Tarif ohne Grundgebühr: http://www.gmx.net/dsl
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org