Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>[Replaced my last answer. Now I understand better what you need.]</p> <p>Here's an XSLT 2.0 solution:</p> <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:template match="/root"&gt; &lt;xsl:variable name="elements-after" select="t|u|v|w|x|y|z"/&gt; &lt;xsl:copy&gt; &lt;xsl:copy-of select="* except $elements-after"/&gt; &lt;s&gt;new node&lt;/s&gt; &lt;xsl:copy-of select="$elements-after"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>You have to explicitly list either the elements that come after or the elements that come before. (You don't have to list both.) I would tend to choose the shorter of the two lists (hence "t" - "z" in the above example, instead of "a" - "r").</p> <p>OPTIONAL ENHANCEMENT:</p> <p>This gets the job done, but now you need to maintain the list of element names in two different places (in the XSLT and in the schema). If it changes much, then they might get out of sync. If you add a new element to the schema but forget to add it to the XSLT, then it won't get copied through. If you're worried about this, you can implement your own sort of schema awareness. Let's say your schema looks like this:</p> <pre><code>&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; &lt;xs:element name="root"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name="a" type="xs:string"/&gt; &lt;xs:element name="r" type="xs:string"/&gt; &lt;xs:element name="s" type="xs:string"/&gt; &lt;xs:element name="t" type="xs:string"/&gt; &lt;xs:element name="z" type="xs:string"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:schema&gt; </code></pre> <p>Now all you need to do is change your definition of the $elements-after variable:</p> <pre><code> &lt;xsl:variable name="elements-after" as="element()*"&gt; &lt;xsl:variable name="root-decl" select="document('root.xsd')/*/xs:element[@name eq 'root']"/&gt; &lt;xsl:variable name="child-decls" select="$root-decl/xs:complexType/xs:sequence/xs:element"/&gt; &lt;xsl:variable name="decls-after" select="$child-decls[preceding-sibling::xs:element[@name eq 's']]"/&gt; &lt;xsl:sequence select="*[local-name() = $decls-after/@name]"/&gt; &lt;/xsl:variable&gt; </code></pre> <p>This is obviously more complicated, but now you don't have to list any elements (other than "s") in your code. The script's behavior will automatically update whenever you change the schema (in particular, if you were to add new elements). Whether this is overkill or not depends on your project. I offer it simply as an optional add-on. :-)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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