title: Translate XSLT transformation to C#
body: <p>I am struggling with understanding an XSLT transformation. Currently I receive a serialized object in XML format, then apply XSLT and send new XML back the program. But now I need to eliminate XSLT step and to do the transformation internally in the program. The problem is I've seen XSLT sheet for the second time. Transformation sheet look really simmple but I still cannot undersnad what is going on there.  </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:t="http://tempuri.org/"&gt;
    &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt;
    &lt;xsl:strip-space elements="*"/&gt;
    &lt;xsl:template name="CopyEverything" 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="/t:Data/Flagged"&gt;
      &lt;xsl:element name="Flagged"&gt;
        &lt;xsl:apply-templates select="/t:Data/Covers/node()|@*"/&gt;
      &lt;/xsl:element&gt;
    &lt;/xsl:template&gt;
    &lt;xsl:template match="/t:Data/FlaggedDetails"&gt;
      &lt;xsl:element name="FlaggedDetails"&gt;
        &lt;xsl:apply-templates select="/t:Data/TotalFlaggedDetails/node()|@*"/&gt;
      &lt;/xsl:element&gt;
    &lt;/xsl:template&gt;
    &lt;xsl:template match="/t:Data/System/RArray"&gt;
      &lt;xsl:element name="{local-name()}"&gt;
        &lt;xsl:for-each select="/t:Data/System/RArray/Elem"&gt;
          &lt;xsl:call-template name="CopyEverything"/&gt;
        &lt;/xsl:for-each&gt;
        &lt;xsl:for-each select="/t:Data/Elem/Elem"&gt;
          &lt;xsl:variable name="currentCode" select="Code" /&gt;
          &lt;xsl:variable name="showAlways" select="ShowAlways" /&gt;
          &lt;xsl:if test="count(/t:Data/System/RArray/Elem[Code=$currentCode])=0"&gt;
            &lt;xsl:call-template name="CopyEverything"/&gt;
          &lt;/xsl:if&gt;
        &lt;/xsl:for-each&gt;
      &lt;/xsl:element&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>As far as I understand something from Data/Flagged and Data/FlaggedDetails is copied to Data/System/RArray, I cannot translate this logic to C#. I have to eliminate serialization stemps, so I move objects between collections (if this is what is going on) without XSLT. Could someone help me on this?</p>