<div dir="ltr"><div><div><div>Hi list --<br><br></div>I'm trying to get a better understanding of identity transforms in Xquery and I don't understand the finer points of the approaches for dealing with specific elements. <br><br></div>I've finally to become used to the XSLT approach, using a matching template to process `field[@name='first']`, e.g. would someone be willing to shine some light on different methods for dealing with this?<br><br></div><div>Thanks very much for your time and trouble.<br></div><div>Best,<br></div><div>Bridger<br></div><div><br></div><div>Example:<br></div><div><div><pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"PT Mono";font-size:9.4pt"><span style="color:rgb(0,0,255)">declare variable </span>$input :=<br>  <<span style="color:rgb(142,73,179);font-weight:bold">docs</span>><br>    <<span style="color:rgb(142,73,179);font-weight:bold">doc</span>><br>      <<span style="color:rgb(142,73,179);font-weight:bold">title</span>>ABC: The Alphabet</<span style="color:rgb(142,73,179);font-weight:bold">title</span>><br>      <<span style="color:rgb(142,73,179);font-weight:bold">author</span>>Some Person</<span style="color:rgb(142,73,179);font-weight:bold">author</span>><br>      <<span style="color:rgb(142,73,179);font-weight:bold">fields</span>><br>        <<span style="color:rgb(142,73,179);font-weight:bold">field </span><span style="color:rgb(255,96,46)">name=</span><span style="color:rgb(0,128,0)">"first"</span>>First Field</<span style="color:rgb(142,73,179);font-weight:bold">field</span>><br>        <<span style="color:rgb(142,73,179);font-weight:bold">field </span><span style="color:rgb(255,96,46)">name=</span><span style="color:rgb(0,128,0)">"second"</span>>Second Field</<span style="color:rgb(142,73,179);font-weight:bold">field</span>><br>      </<span style="color:rgb(142,73,179);font-weight:bold">fields</span>><br>    </<span style="color:rgb(142,73,179);font-weight:bold">doc</span>><br>  </<span style="color:rgb(142,73,179);font-weight:bold">docs</span>>;<br><br><span style="color:rgb(0,0,255)">declare function </span>local:passthru( $node <span style="color:rgb(0,0,255)">as node</span>()* ){<br>  local:dispatch($node/<span style="color:rgb(0,0,255)">node</span>())<br>};<br><br><span style="color:rgb(0,0,255)">declare function </span>local:dispatch(<br>  $nodes <span style="color:rgb(0,0,255)">as node</span>()*<br>) <span style="color:rgb(0,0,255)">as item</span>()* {<br>  <span style="color:rgb(0,0,255)">for </span>$node <span style="color:rgb(0,0,255)">in </span>$nodes<br>  <span style="color:rgb(0,0,255)">return<br></span><span style="color:rgb(0,0,255)">    typeswitch</span>($node)<br>      <span style="color:rgb(0,0,255)">case text</span>() <span style="color:rgb(0,0,255)">return </span>$node<br>      <span style="color:rgb(0,0,255)">case element</span>(docs) <span style="color:rgb(0,0,255)">return </span>local:passthru($node)<br>      <span style="color:rgb(0,0,255)">case element</span>(doc) <span style="color:rgb(0,0,255)">return </span>local:docf($node)<br>      <span style="color:rgb(0,0,255)">case element</span>(title) <span style="color:rgb(0,0,255)">return </span>local:title($node)<br>      <span style="color:rgb(0,0,255)">case element</span>(author) <span style="color:rgb(0,0,255)">return </span>local:author($node)<br>      <span style="color:rgb(0,0,255)">case element</span>(fields) <span style="color:rgb(0,0,255)">return </span>local:passthru($node)<br>      <span style="color:rgb(0,0,255)">case element</span>(field) <span style="color:rgb(0,0,255)">return </span>() <span style="color:rgb(128,128,128);font-style:italic">(:return empty sequence:)<br></span><span style="color:rgb(128,128,128);font-style:italic">      </span><span style="color:rgb(0,0,255)">default return </span>local:passthru($node)<br>};<br><br><span style="color:rgb(0,0,255)">declare function </span>local:docf($node) {<br>  <<span style="color:rgb(142,73,179);font-weight:bold">new</span>>{local:dispatch($node/<span style="color:rgb(0,0,255)">node</span>())}</<span style="color:rgb(142,73,179);font-weight:bold">new</span>><br>};<br><br><span style="color:rgb(0,0,255)">declare function </span>local:title($node) {<br>  <<span style="color:rgb(142,73,179);font-weight:bold">new-title</span>>{local:dispatch($node/<span style="color:rgb(0,0,255)">node</span>())}</<span style="color:rgb(142,73,179);font-weight:bold">new-title</span>><br>};<br><br><span style="color:rgb(0,0,255)">declare function </span>local:author($node) {<br>  <<span style="color:rgb(142,73,179);font-weight:bold">new-author</span>>{local:dispatch($node/<span style="color:rgb(0,0,255)">node</span>())}</<span style="color:rgb(142,73,179);font-weight:bold">new-author</span>><br>};<br><br>local:dispatch($input)<br><br></pre><pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"PT Mono";font-size:9.4pt"><font face="arial,helvetica,sans-serif">Ou<font face="arial,helvetica,sans-serif">tput should look some<font face="arial,helvetica,sans-serif">thing like:<br></font></font></font><br><font face="arial,helvetica,sans-serif"><font face="arial,helvetica,sans-serif"><font face="arial,helvetica,sans-serif"><<span style="color:rgb(142,73,179);font-weight:bold">new</span>><br>  <<span style="color:rgb(142,73,179);font-weight:bold">new-title</span>>ABC: The Alphabet</<span style="color:rgb(142,73,179);font-weight:bold">new-title</span>><br>  <<span style="color:rgb(142,73,179);font-weight:bold">new-author</span>>Some Person</<span style="color:rgb(142,73,179);font-weight:bold">new-author</span>><br>  <<span style="color:rgb(142,73,179);font-weight:bold">new-subject</span>>First Field</<span style="color:rgb(142,73,179);font-weight:bold">new-subject</span>><br>  <<span style="color:rgb(142,73,179);font-weight:bold">new-section</span>><br>    <<span style="color:rgb(142,73,179);font-weight:bold">new-entry</span>>Second Field</<span style="color:rgb(142,73,179);font-weight:bold">new-entry</span>><br>  </<span style="color:rgb(142,73,179);font-weight:bold">new-section</span>><br></<span style="color:rgb(142,73,179);font-weight:bold">new</span>></font></font></font></pre></div></div></div>