title: how to transform a parameter using value-of and select
body: <p>I am using xslt to transform an xml document into another xml document.</p>
  
  <p>in the below code it's only getting the value of the email address for the first review and using that for all the reviews, instead of getting the email address for each review.  I know it's not good to use // but when I just use Review/UserEmailAddress the value is blank and I don't know how else to do it. </p>
  
  <p>Here's my input xml:</p>
  
  <pre><code>&lt;Product id="867776000050"&gt;
  &lt;ExternalId&gt;867776000050&lt;/ExternalId&gt;
  &lt;Reviews&gt;
      &lt;Review id="3924" removed="false"&gt;
           &lt;UserProfileReference id="Haliley"&gt;
              &lt;ExternalId&gt;Haliley&lt;/ExternalId&gt;
              &lt;DisplayName&gt;Haliley&lt;/DisplayName&gt;
          &lt;/UserProfileReference&gt;
          &lt;UserEmailAddress&gt;hbonb@yahoo.com&lt;/UserEmailAddress&gt;
      &lt;/Review&gt;
      &lt;Review id="3919" removed="false"&gt;
          &lt;UserProfileReference id="PaulineTincher"&gt;
              &lt;ExternalId&gt;PaulineTincher&lt;/ExternalId&gt;
              &lt;DisplayName&gt;PaulineTincher&lt;/DisplayName&gt;
          &lt;/UserProfileReference&gt;
          &lt;UserEmailAddress&gt;pt59@msn.com&lt;/UserEmailAddress&gt;
      &lt;/Review&gt;
  &lt;/Reviews&gt;
  &lt;/Product&gt;
  </code></pre>
  
  <p>Here's my stylesheet:</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" 
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:output method="xml" omit-xml-declaration="no" indent="yes"/&gt;
  &lt;xsl:strip-space elements="*"/&gt;
  
  &lt;xsl:template match="node()|@*"&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:apply-templates select="node()|@*"/&gt;
      &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="Review/UserProfileReference"&gt;
      &lt;xsl:variable name="userid"&gt;&lt;xsl:value-of select="ExternalId"/&gt; 
      &lt;xsl:value-of select="substring-before(//Review/UserEmailAddress, '@')"/&gt;&lt;/xsl:variable&gt;
      &lt;UserProfileReference id="{$userid}"&gt;
      &lt;ExternalId&gt;&lt;xsl:value-of select="ExternalId"/&gt;&lt;xsl:value-of select="substring-before(//Review/UserEmailAddress, '@')"/&gt;&lt;/ExternalId&gt;
      &lt;DisplayName&gt;&lt;xsl:value-of select="DisplayName"/&gt;&lt;/DisplayName&gt;
      &lt;/UserProfileReference&gt;
  &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>I am trying to make the UserProfileReference unique by appending the first part of the email address to the existing value.</p>
  
  <p>In my results below the UserProfileReference id value for the first review is correct, it appends the value of the UserEmailAddress to the id.</p>
  
  <p>But for review 2, it uses the email address from review 1, not review 2. I've spent a ton of time on this and just can't figure it out. Please help!</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Product id="867776000050"&gt;
  &lt;ExternalId&gt;867776000050&lt;/ExternalId&gt;
  &lt;Reviews&gt;
      &lt;Review id="3924" removed="false"&gt;
      &lt;UserProfileReference id="Halileyhbonb"&gt;
          &lt;ExternalId&gt;Halileyhbonb&lt;/ExternalId&gt;
          &lt;DisplayName&gt;Haliley&lt;/DisplayName&gt;
      &lt;/UserProfileReference&gt;
      &lt;UserEmailAddress&gt;hbonb@yahoo.com&lt;/UserEmailAddress&gt;
      &lt;/Review&gt;
      &lt;Review id="3919" removed="false"&gt;
      &lt;UserProfileReference id="PaulineTincherhbonb"&gt;
          &lt;ExternalId&gt;PaulineTincherhbonb&lt;/ExternalId&gt;
          &lt;DisplayName&gt;PaulineTincher&lt;/DisplayName&gt;
      &lt;/UserProfileReference&gt;
      &lt;UserEmailAddress&gt;pt59@msn.com&lt;/UserEmailAddress&gt;
      &lt;/Review&gt;
  &lt;/Reviews&gt;
  &lt;/Product&gt;
  </code></pre>