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" <[EMAIL PROTECTED]>
12/05/2004 10:31
|
To: [EMAIL PROTECTED] 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>[EMAIL PROTECTED]'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/[EMAIL PROTECTED]'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
[EMAIL PROTECTED]"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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]