cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From laurent_ror...@marinepower.com
Subject Re: Conditional replace / reinsert with SourceWritingTransformer
Date Fri, 14 May 2004 12:04:46 GMT
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" <stephanie.zohner@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



Mime
View raw message