Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Change from <code>&lt;xsl:template&gt;</code> to <code>&lt;xsl:apply-templates&gt;</code></p> <pre><code>&lt;xsl:apply-templates select="/data/peptides/peptide[generate-id()=generate-id(key('byAccSeq', concat(protein_accessions/accession, '|', sequence))[1])]" mode="type1" /&gt; &lt;xsl:apply-templates select="/data/peptides/peptide[generate-id()=generate-id(key('byAccSeq', concat(protein_accessions/accession, '|', sequence)))]" mode="type2" /&gt; </code></pre> <p>After that, write <code>&lt;xsl:template&gt;</code> for both or in one accordingly.</p> <h1>Modify your solution in shorter way:</h1> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/&gt; &lt;xsl:key name="byAccSeq" match="/data/peptides/peptide" use="concat(accession, '|', sequence)"/&gt; &lt;xsl:param name="analysis" select="2"/&gt; &lt;xsl:template match="/"&gt; &lt;root&gt; &lt;name&gt; &lt;xsl:value-of select="$analysis"/&gt; &lt;/name&gt; &lt;xsl:apply-templates select="data[peptides/peptide/accession=proteins/protein/accession]/peptides" /&gt; &lt;/root&gt; &lt;/xsl:template&gt; &lt;xsl:template match="peptides"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="$analysis=1"&gt; &lt;xsl:copy-of select="peptide"/&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:for-each select="peptide[generate-id()=generate-id(key('byAccSeq', concat(accession, '|', sequence)))]"&gt; &lt;xsl:copy-of select="."/&gt; &lt;/xsl:for-each&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>I have tested my code as per your input XML &amp; output. Now I can replicate the same.</p> <p>On my code, still I can reduce some more lines of code</p> <p>Replace <code>&lt;xsl:for-each&gt;</code> with below line:-</p> <pre><code>&lt;xsl:copy-of select="peptide[generate-id()=generate-id(key('byAccSeq', concat(accession, '|', sequence)))]"/&gt; </code></pre> <p>Check it out..</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