Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A much cleaner, simpler and efficient solution is to use template matching instead of tortuous branching. I am assuming XSLT 2.0 because you did not tag your question with the XSLT version number, but if you need XSLT 1.0, then adjustments can easily be made.</p> <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output indent="yes" omit-xml-declaration="yes" /&gt; &lt;xsl:strip-space elements="*" /&gt; &lt;xsl:variable name="filter" select="document('filter.xml')/*" /&gt; &lt;xsl:template match="/" &gt; &lt;root&gt; &lt;xsl:apply-templates select="*/item" /&gt; &lt;/root&gt; &lt;/xsl:template&gt; &lt;xsl:template match="item[server=$filter/Bloc5/Part1/EAN]" &gt; &lt;item&gt; &lt;server&gt;MAIN&lt;/server&gt; &lt;status&gt;PRODUCTION&lt;/status&gt; &lt;/item&gt; &lt;/xsl:template&gt; &lt;xsl:template match="item[server=$filter/Bloc5/Part2/EAN]" &gt; &lt;item&gt; &lt;server&gt;BACKUP&lt;/server&gt; &lt;status&gt;STOPPED&lt;/status&gt; &lt;/item&gt; &lt;/xsl:template&gt; &lt;xsl:template match="item" &gt; &lt;item&gt; &lt;name&gt;OFFLINE&lt;/name&gt; &lt;desc&gt;Production&lt;/desc&gt; &lt;/item&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <hr> <h1>Update: Icing on the cake</h1> <p>Thanks for your acceptance. As icing on the cake, you could also replace the first two item templates with this <em>ONE</em> more generic and extensible template. But it's debatable whether it is more simpler or more complex.</p> <p>Alternative generic item template (only works for XSLT 2.0) ...</p> <pre><code>&lt;xsl:template match="item[server=$filter/Bloc5/*/EAN]" &gt; &lt;xsl:variable name="part-no" select="substring-after(local-name(($filter/Bloc5/*[EAN=current()/server])[1]), 'Part') cast as xs:integer" /&gt; &lt;xsl:copy&gt; &lt;server&gt;&lt;xsl:value-of select="('MAIN' ,'BACKUP' )[$part-no]" /&gt;&lt;/server&gt; &lt;status&gt;&lt;xsl:value-of select="('PRODUCTION','STOPPED')[$part-no]" /&gt;&lt;/status&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; </code></pre>
    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