title: Using XSLT Apply-Templates to conditionally select nodes
body: <p>Let's say I have an xml document like this:</p>
  
  <pre><code>&lt;director&gt;
      &lt;play&gt;
          &lt;t&gt;Nutcracker&lt;/t&gt;
          &lt;a&gt;Tom Cruise&lt;/a&gt;
      &lt;/play&gt;
      &lt;play&gt;
          &lt;t&gt;Nutcracker&lt;/t&gt;
          &lt;a&gt;Robin Williams&lt;/a&gt;
      &lt;/play&gt;
      &lt;play&gt;
          &lt;t&gt;Grinch Stole Christmas&lt;/t&gt;
          &lt;a&gt;Will Smith&lt;/a&gt;
      &lt;/play&gt;
      &lt;play&gt;
          &lt;t&gt;Grinch Stole Christmas&lt;/t&gt;
          &lt;a&gt;Mel Gibson&lt;/a&gt;
      &lt;/play&gt;
  &lt;/director&gt;
  </code></pre>
  
  <p>Now I want to be able to select all the plays with Will Smith as an actor and reformat it into something like this:</p>
  
  <pre><code>&lt;Plays&gt;
      &lt;Play title="Grinch Stole Christmas"&gt;
         &lt;star&gt;Will Smith&lt;/star&gt;
         &lt;star&gt;Mel Gibson&lt;/star&gt;
      &lt;/Play&gt;
  &lt;/Plays&gt;
  </code></pre>
  
  <p>I only want to use apply-templates.. No xsl:if or for each loops (I have contrived this example as a simpler version of what I'm doing so you can help me understand how to use xpath within a match statement)</p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:output method="xml" indent="yes" /&gt;
          &lt;xsl:template match="/director"&gt;
                  &lt;Plays&gt;
                  &lt;xsl:apply-templates select="play"/&gt;
                  &lt;/Plays&gt;
          &lt;/xsl:template&gt;
  
          &lt;xsl:template match="play[a='Will Smith']"&gt;
                  &lt;play title="{data(t)[1]}"&gt;
                  &lt;xsl:apply-templates select="a"/&gt;
                  &lt;/play&gt;
          &lt;/xsl:template&gt;
  
          &lt;xsl:template match="a"&gt;
                  &lt;star&gt;
                  &lt;xsl:value-of select="."/&gt;
                  &lt;/star&gt;
          &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Basically I am just unsure of how to filter out nodes using XPath in the match attribute of the template. Any help would be great!</p>