title: TransformXml task with InsertAfter - How to use function?
body: <p>I'm trying to use the <code>&lt;TransformXml&gt;</code> task in my web projects (.csproj/.vbproj) to Transform configuration files and other XML files. I use an msbuild script (powershell) to build and package my code and generate environment-based transformed configuration and XML files.</p>
  
  <p>This all works perfectly for simple usages such as <code>Match</code>, <code>Condition</code>, <code>SetAttributes</code> and so on, but I've recently tried to be a bit clever and use an <strong>XPath</strong> locator to find the <strong>last node</strong> in a group of nodes in order to <em>only</em> set the attributes of that last node. Additionally, I want to insert a new node after the last node, with some extra attributes.</p>
  
  <p>When trying this syntax:</p>
  
  <pre><code>&lt;parent&gt;
      &lt;a xdt:Transform="SetAttributes(from)" xdt:Locator="XPath(/a[ancestor-or-self::section[last()]])" from="20130522" /&gt;
            &lt;a xdt:Transform="SetAttributes(to)" xdt:Locator="XPath(/a[ancestor-or-self::section[last()]])" to="20130630" /&gt;
            &lt;a xdt:Transform="InsertAfter(XPath(/a[ancestor-or-self::section[last()]]))" from="20130701" to="20140101" /&gt;
  &lt;/parent&gt;
  </code></pre>
  
  <p>on XML (shortened) that looks approximately like this:</p>
  
  <pre><code>&lt;parent&gt;
    &lt;a from="xxx1" to="yyy1"&gt;
      &lt;one&gt;one&lt;/one&gt;
      &lt;two&gt;two&lt;/two&gt;
    &lt;/a&gt;
    &lt;a from="xxx2" to="yyy2"&gt;
      &lt;one&gt;one&lt;/one&gt;
      &lt;two&gt;two&lt;/two&gt;
    &lt;/a&gt;
    &lt;a from="xxx3" to="yyy3"&gt;
      &lt;one&gt;one&lt;/one&gt;
      &lt;two&gt;two&lt;/two&gt;
    &lt;/a&gt;
  &lt;/parent&gt;
  </code></pre>
  
  <p>... I get the familiar (and expected) error</p>
  
  <p><code>Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.</code></p>
  
  <p>All the answers I can find for this revolve around using code to specify a Namespace manager, which makes perfect sense - but I have no code for this process, it's all within the scope of a <code>TransformXml</code> task and plain XML. I don't know which part of the XPath query is causing this error to occur, or how I can specify the type of task I need to run.</p>
  
  <p>How can I accomplish this? Is it even possible to do this type of node manipulation within a transform?</p>
  
  <p>Thanks</p>
  
  <p><strong>Edit:</strong> I can now see that the error is occurring on the InsertAfter call and not the SetAttributes - so it's this part that appears to be causing the issue.</p>