Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I can think of two ways to do this. </p> <p>1) identity template, hard coded author name:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" &gt; &lt;xsl:template match="node()|@*"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*" /&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;!-- nodepads generally get removed... --&gt; &lt;xsl:template match="notepad" /&gt; &lt;!-- ...unless their author is 'Jon Doe' --&gt; &lt;xsl:template match="notepad[author='John Doe']"&gt; &lt;xsl:copy-of select="." /&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>2) modified identity template, XSL key, parameterized author name:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" &gt; &lt;xsl:param name="theAuthor" select="'John Doe'" /&gt; &lt;xsl:key name="kNotepad" match="notepad[author]" use="concat(generate-id(..), '|', author)" /&gt; &lt;xsl:template match="node()|@*"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select=" node()[not(self::notepad)] |key('kNotepad', concat(generate-id(), '|', $theAuthor)) |@*" /&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>The second approach requires a little explanation:</p> <ul> <li>the <code>&lt;xsl:key&gt;</code> indexes all <code>&lt;nodepad&gt;</code> nodes that have an <code>&lt;author&gt;</code> by their parent's unique ID and the author name</li> <li>let's say the unique ID of <code>&lt;notepads&gt;</code> is <code>'id0815'</code>, then the key to the <code>&lt;notepad&gt;</code>s you are interested in would be <code>'id0815|Jon Doe'</code></li> <li>the identity template copies every node that is passed through it. It is modified in a way that it does <em>not</em> pass every node it finds through itself, but rather only: <ul> <li>any node that is not a <code>&lt;notepad&gt;</code>: <code>node()[not(self::notepad)]</code></li> <li>any attribute: <code>@*</code></li> <li>any node that is returned by the key.</li> </ul></li> <li>the call to <code>key()</code> naturally only ever returns anything at all on <code>&lt;notepads&gt;</code> elements (because it contains <em>their</em> unique ID)</li> <li>so when the template is currently processing a <code>&lt;notepads&gt;</code> element (<code>'id0815'</code> in our case), <code>key()</code> will return its <code>'Jon Doe'</code> children only, in all other cases it will turn up empty</li> <li>in contrast to solution 1) this one can be fed with a parameter, changing its behavior without changing its code</li> <li>it is worth noting that everything stays in input document order</li> </ul>
    singulars
    1. This table or related slice is empty.
    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.
 

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