Note that there are some explanatory texts on larger screens.

plurals
  1. POSelecting the unique values from multiple attributes in an XML document using XSLT 1.0
    text
    copied!<p>I have the following XML:</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>What I would like to do is get a unique list of all the Team Ids within that XML, but the problem is that team ids can either appear in the <code>HomeTeamId</code> or the <code>AwayTeamId</code> attributes in the fixture nodes. So I'm struggling to use the standard grouping methods (<a href="http://www.jenitennison.com/xslt/grouping/muenchian.html" rel="nofollow noreferrer">Grouping using the Muenchian method</a> or <a href="https://stackoverflow.com/questions/227711/how-to-select-unique-nodes-in-xslt">selecting unique nodes by checking the preceding sibling</a>).</p> <p>I can get a list of all the ids this way:</p> <pre><code>&lt;xsl:for-each select="//Fixture/@HomeTeamId | //Fixture/@AwayTeamId"&gt; &lt;xsl:sort select="."/&gt; &lt;xsl:value-of select="."/&gt;&lt;br/&gt; &lt;/xsl:for-each&gt; </code></pre> <p>But of course when the teams appear in more than one fixture, their id is output more than once using the for-each above.</p> <p>My ultimate aim is to output a list of fixtures grouped by each team, but I'm struggling with the XSLT here - it's making my brain hurt... Can anyone point me in the right direction?</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