<div dir="auto">Untested XSLT 1.0 and 2.0. YMMV!</div><div dir="auto"><br></div><div dir="auto">Prompt:</div><div dir="auto"><br></div><div dir="auto"><div style="font-size:inherit"><span style="font-family:"anthropic sans",system-ui,"segoe ui",roboto,helvetica,arial,sans-serif;font-size:inherit;font-style:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;text-decoration:none;float:none;display:inline!important;background-color:rgb(240,238,230);color:rgb(20,20,19)">in XSLT, how do I find the first node with an attribute with a the  name USE, but the same value as and before  a node with the attribute with the name DEF.  Swap the two nodes, then do this for all nodes that have DEF and USE.  The nodes swapped should have the same tag.</span></div><br></div><div dir="auto">Response:</div><div dir="auto"><br></div><div dir="auto"><div style="font-size:inherit" dir="auto">This is the <div style="font-size:inherit" dir="auto"><strong style="font-style:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;font-size:inherit;color:rgb(0,0,0)">identity-transform-with-selective-swap</strong><span style="font-style:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;font-size:inherit;color:rgb(0,0,0)"> if you’re not going to use AI.</span></div><div style="font-size:inherit" dir="auto"><br></div></div></div><div dir="auto"><br></div><div dir="auto"><div style="font-size:inherit"><a href="https://claude.ai/share/ea29239f-adc6-4dbd-b84c-a49ba8413c83" style="font-size:inherit">https://claude.ai/share/ea29239f-adc6-4dbd-b84c-a49ba8413c83</a></div><br></div><div dir="auto">Please test thoroughly if you’re going to use this.  And use proper attribution, of course!</div><div dir="auto"><br></div><div dir="auto">Hoping that we can see something like this soon, I might try it in my pipeline, if no one else cares to try it.  But I would have to dig into the guts of X3DJSAIL, and that stylesheet is super scary!</div><div dir="auto"><br></div><div dir="auto">John </div><div dir="auto"><br><div class="gmail_quote gmail_quote_container" dir="auto"><div dir="ltr" class="gmail_attr">On Sat, Mar 28, 2026 at 3:28 AM John Carlson <<a href="mailto:yottzumm@gmail.com">yottzumm@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)"><div dir="auto">Finding nodes before or after a node in XSLT.  Google search.</div><div dir="auto"><br></div><div dir="auto">John </div><div dir="auto"><br></div><div dir="auto"><div><img src="cid:ii_19d338d2e57d9aa668e1" style="width: 461px; max-width: 100%;"></div><br></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 28, 2026 at 3:17 AM John Carlson <<a href="mailto:yottzumm@gmail.com" target="_blank">yottzumm@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)"><div dir="auto">path() in XSLT:  <div style="font-size:inherit"><a href="https://stackoverflow.com/questions/38602029/generate-xpath-from-node-using-xslt-2#:~:text=Comments,-Add%20a%20comment&text=A%20couple%20of%20points.,element%20names%20are%20context%2Dfree." style="font-size:inherit" target="_blank">https://stackoverflow.com/questions/38602029/generate-xpath-from-node-using-xslt-2#:~:text=Comments,-Add%20a%20comment&text=A%20couple%20of%20points.,element%20names%20are%20context%2Dfree.</a></div><div style="font-size:inherit" dir="auto"><br></div><div style="font-size:inherit" dir="auto">Read Michael Kay’s comment before using his code….</div></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 28, 2026 at 2:59 AM John Carlson <<a href="mailto:yottzumm@gmail.com" target="_blank">yottzumm@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)">The issue with why there’s no DEF/USE reordering in X3DJSAIL and X3DPSAIL apparently stems from Saxon not being able to handle mutable maps/lookup tables.  So let’s build a map per scene, but don’t build it in the X3dTo….xslt, <span>but as a generated XSLT map, perhaps in another file, XSLT or not.</span><div dir="auto"><div dir="auto"><br></div><div dir="auto">Perhaps we need to write a preprocessor to map DEF/USE values to a list of XPath expressions in a file per XML scene which allows the DEF node and first USE node for a particular DEF value to be found with an XPath.  If the DEF node isn’t the first XPath for a given DEF/USE value, then the DEF node is swapped with the first USE node with the same DEF value.  We can probably export this as a stylesheet per XML scene.<div dir="auto"><br></div><div dir="auto">Will this actually work?</div><div dir="auto"><br></div><div dir="auto">Criticism welcome!</div><div dir="auto"><br></div><div dir="auto">I’d say Don could probably whip this up really quick if he can retrieve XPaths for all DEF and USE nodes in a scene.  Maybe Vince could as well.  What implementation language do we use?</div><div dir="auto"><br></div><div dir="auto">Do PROTOs affect this?</div><div dir="auto"><br></div><div dir="auto">Sorry for all the emails today!</div><div dir="auto"><br></div><div dir="auto">I finally got outside the box as they used to say.</div></div></div><div dir="auto"><div dir="auto"><div dir="auto"><br></div><div dir="auto">John </div></div></div>
</blockquote></div></div>
</blockquote></div></div>
</blockquote></div></div>