Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to effeciently modify a large xml document slightly with Microsoft xslt 1.0
    text
    copied!<p>I would like to transform this xml:</p> <pre><code>&lt;Root&gt; &lt;Result&gt; &lt;Message&gt; &lt;Header&gt; &lt;!-- Hundreds of child nodes --&gt; &lt;/Header&gt; &lt;Body&gt; &lt;Node1&gt; &lt;!-- Hundreds of child nodes --&gt; &lt;Node2&gt; &lt;!-- Hundreds of child nodes --&gt; &lt;Node3&gt; &lt;!-- Hundreds of child nodes --&gt; &lt;NodeX&gt;value 1 to be changed&lt;/NodeX&gt; &lt;!-- Hundreds of child nodes --&gt; &lt;Node4&gt; &lt;!-- Hundreds of child nodes --&gt; &lt;NodeY&gt;value 2 to be changed&lt;/NodeY&gt; &lt;/Node4&gt; &lt;/Node3&gt; &lt;/Node2&gt; &lt;/Node1&gt; &lt;/Body&gt; &lt;RealValuesRoot&gt; &lt;!-- These two nodes --&gt; &lt;Value ID="1"&gt;this value must replace the value of Node X&lt;/Value&gt; &lt;Value ID="2"&gt;this value must replace the value of Node Y&lt;/Value&gt; &lt;/RealValuesRoot&gt; &lt;/Message&gt; &lt;/Result&gt; &lt;!-- Hundreds to thousands of similar MessageRoot nodes --&gt; &lt;/Root&gt; </code></pre> <p>Into this xml:</p> <pre><code>&lt;Root&gt; &lt;Result&gt; &lt;Message&gt; &lt;Header&gt; &lt;!-- Hundreds of child nodes --&gt; &lt;/Header&gt; &lt;Body&gt; &lt;Node1&gt; &lt;!-- Hundreds of child nodes --&gt; &lt;Node2&gt; &lt;!-- Hundreds of child nodes --&gt; &lt;Node3&gt; &lt;!-- Hundreds of child nodes --&gt; &lt;NodeX&gt;this value must replace the value of Node X&lt;/NodeX&gt; &lt;!-- Hundreds of child nodes --&gt; &lt;Node4&gt; &lt;!-- Hundreds of child nodes --&gt; &lt;NodeY&gt;this value must replace the value of Node Y&lt;/NodeY&gt; &lt;/Node4&gt; &lt;/Node3&gt; &lt;/Node2&gt; &lt;/Node1&gt; &lt;/Body&gt; &lt;/Message&gt; &lt;/Result&gt; &lt;!-- Hundreds to thousands of similar MessageRoot nodes --&gt; &lt;/Root&gt; </code></pre> <p>The output is almost identical to the input except for the following changes:</p> <ol> <li>The X and Y node values must be replaced with the values of the /RealValuesRoot/Value nodes.</li> <li>The /RealValuesRoot node must be removed from the output.</li> <li>The rest of the xml must remain the same in the output.</li> </ol> <p>The "Value" nodes have unique IDs that represent unique xpaths in the body of the message, e.g. ID 1 refres to xpath /Message/Body/Node1/Node2/Node3/NodeX.</p> <p>I have to use Microsoft’s xslt version 1.0!!</p> <p>I already have an xslt that works fine and does everything I want, yet I am not satisfied with the performance!</p> <p>My xslt works as follows:</p> <ol> <li><p>I created a global string variable that acts like a key value pair, something like: 1:xpath1_2:xpath2_ … _N:xpathN. This variable relates the IDs of the "Value" nodes to the nodes in the message body that need to be replaced.</p></li> <li><p>The xslt iterates the input xml recursively starting from the root node.</p></li> <li><p>I compute the xpath for the current node then do one of the following:</p> <ol> <li>If the current xpath completely matches one of the xpaths in the global list then I replace its value with the value of the corresponding "Value" node and continue the iteration.</li> <li>If the current xpath refers to the "RealValuesRoot" node then I omit that node (don’t copy it to the output) and continue to iterate recursively.</li> <li>If the current xpath does not exist in the global ID-xpath string then I copy the complete node to the output and continue the iteration. (this happens e.g. in the /Message/Header node that will never contain any nodes that need to be replaced)</li> <li>If the current xpath partially matches one of the xpaths in the global list then I simply continue to iterate recursively until I reach one of the 3 cases above.</li> </ol></li> </ol> <p>As said, my xslt works fine but I would like to improve the performance as much as possible, please feel free to suggest a complete new xslt logic! your ideas and suggestions are welcomed!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload