Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>This transformation produces the unique team ids even if their values belonged to any number of differently named attributes</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="my:my" exclude-result-prefixes="my"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:key name="kTeamById" match="@*[name()=document('')/*/my:teamIdNames/*]" use="."/&gt; &lt;my:teamIdNames&gt; &lt;name&gt;HomeTeamId&lt;/name&gt; &lt;name&gt;AwayTeamId&lt;/name&gt; &lt;/my:teamIdNames&gt; &lt;xsl:variable name="vAttrNames" select= "document('')/*/my:teamIdNames/*"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:apply-templates select= "//Fixture/@*[name()=$vAttrNames]"/&gt; &lt;/xsl:template&gt; &lt;xsl:template match= "@*[name()=document('')/*/my:teamIdNames/*] [generate-id() = generate-id(key('kTeamById', .)[1]) ] "&gt; &lt;xsl:value-of select="."/&gt;&lt;br /&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when this transformation is applied on the provided XML document:</strong></p> <pre><code>&lt;League&gt; &lt;Week Date="26/04/2010 19:00"&gt; &lt;Fixture Id="542" HomeTeamId="371" HomeTeam="London Raiders Green" AwayTeamId="13" AwayTeam="Richmond Swingers"/&gt; &lt;Fixture Id="543" HomeTeamId="45" HomeTeam="Spartans" AwayTeamId="15" AwayTeam="Panthers"/&gt; &lt;Fixture Id="544" HomeTeamId="370" HomeTeam="Fat Cats" AwayTeamId="381" AwayTeam="London Raiders Orange" /&gt; &lt;/Week&gt; &lt;Week Date="27/04/2010 19:00"&gt; &lt;Fixture Id="548" HomeTeamId="3" HomeTeam="The Mob" AwayTeamId="81" AwayTeam="London Raiders Red"/&gt; &lt;Fixture Id="549" HomeTeamId="373" HomeTeam="Intellect" AwayTeamId="83" AwayTeam="Tornadoes"/&gt; &lt;/Week&gt; &lt;/League&gt; </code></pre> <p><strong>the wanted result is produced</strong>:</p> <pre><code>371&lt;br/&gt;13&lt;br/&gt;45&lt;br/&gt;15&lt;br/&gt;370&lt;br/&gt;381&lt;br/&gt;3&lt;br/&gt;81&lt;br/&gt;373&lt;br/&gt;83&lt;br/&gt; </code></pre> <p><strong>Do note</strong>:</p> <p><strong>This solution doesn't assume</strong> that the sources of the ids for the teams come just from the attributes named <code>HomeTeamId</code> and <code>AwayTeamId</code>. </p> <p><strong>In fact, any variable set of names can be used</strong> (and included in a separate document), so this is a very powerful, generic solution.</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. 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