Subject:Parametized search and replace for XML elements Author:V. Caspi Date:10 Oct 2006 07:05 AM
Hi,
I'm very new in working with XSLT. I need to define a transformation which gets as parameters: 1) XML element name and 2) new value for it and replaces all the XML elements with this name with the new value.
I've managed doing it with attributes (see example below), but have difficulties with element name match parameterization in templates etc.
Subject:Parametized search and replace for XML elements Author:V. Caspi Date:10 Oct 2006 11:21 AM
Thank you, Ivan! :-)
Actually I've solved the problem already. So, I'll try to describe it better together with the solution.
I have some XML structured like that:
<row>
<a>..</a>
<b>..</b>
<c>..</c>
....
</row>
<row>
...........
I get a map of row fields to be updated together with their new values.
Each field is mapped to an XML element.
E.g., a: 23, c:12.
And I need to update all the elements appearances.
What I wanted to to is to create some generic XSLT definition file, which gets elementName and elementValue (inner text) and to run it in a loop for each parameter. This decision put me into troubles. Still I don't know how can it be done in an elegant generic way.
So, my solution was dynamic creation of the following XSLT definition file based on a common header and footer, while concatenating to it template nodes for each parameter field I need to update.
The following example shows the XSLT file built for parameters named 'b' and 'c'.