title: Transforming a XML according to a XSD using XSLT
body: <p>I would like to create a XSLT that can transform a XML so that all of the elements and attributes that is not defined in the XSD is excluded in the output XML (from the XSLT).</p>
  
  <p>Lets say you have this XSD.</p>
  
  <pre><code>&lt;xs:element name="parent"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="keptElement1" /&gt;
              &lt;xs:element name="keptElement2" /&gt;
          &lt;/xs:sequence&gt;
  
          &lt;xs:attribute name="keptAttribute1" /&gt;
          &lt;xs:attribute name="keptAttribute2" /&gt;
      &lt;/complexType&gt;
  &lt;/xsd:element&gt;
  </code></pre>
  
  <p>And you have this input XML</p>
  
  <pre><code>&lt;parent keptAttribute1="kept" 
      keptAttribute2="kept" 
      notKeptAttribute3="not kept" 
      notKeptAttribute4="not kept"&gt;
  
      &lt;notKeptElement0&gt;not kept&lt;/notKeptElement0&gt;
      &lt;keptElement1&gt;kept&lt;/keptElement1&gt;
      &lt;keptElement2&gt;kept&lt;/keptElement2&gt;
      &lt;notKeptElement3&gt;not kept&lt;/notKeptElement3&gt;
  &lt;/parent&gt;
  </code></pre>
  
  <p>Then i would like to have the output Xml looking like this.</p>
  
  <pre><code>&lt;parent keptAttribute1="kept" 
      keptAttribute2="kept"&gt;
  
      &lt;keptElement1&gt;kept&lt;/keptElement1&gt;
      &lt;keptElement2&gt;kept&lt;/keptElement2&gt;
  &lt;/parent&gt;
  </code></pre>
  
  <p>I am able to do this by specifying the elements, but this is about as far as my xslt skills reach. I have problem doing this generally for all elements and all attributes.</p>