title: XSLT - How to read all child nodes in order, having same and different name tags
body: <p>I have the below XML file that i want to parse to create HTML. My problem is that i am not able to parse it as I would like.</p>
  
  <p>What i want to do is output my <code>&lt;items&gt;</code> as html. So i want a <code>&lt;paragraph&gt;</code> to be a <code>&lt;div&gt;</code>, <code>&lt;image&gt;</code>to be an  <code>&lt;img&gt;</code> and its child nodes to be its properties 'src' and 'alt'.</p>
  
  <pre><code>&lt;itemlist&gt;
      &lt;item&gt;
          &lt;paragraph&gt;pA&lt;/paragraph&gt;
          &lt;image&gt;
              &lt;url&gt;http://www.com/image.jpg&lt;/url&gt;
              &lt;title&gt;default image&lt;/title&gt;
          &lt;/image&gt;
          &lt;paragraph&gt;pB&lt;/paragraph&gt;
          &lt;paragraph&gt;pC&lt;/paragraph&gt;
          &lt;link target='#'&gt;linkA&lt;/link&gt;
          &lt;paragraph&gt;pD&lt;/paragraph&gt;
          &lt;link target='#' &gt;linkB&lt;/link&gt;
          &lt;image&gt;
              &lt;url&gt;http://www.com/image2.jpg&lt;/url&gt;
              &lt;title&gt;default image 2&lt;/title&gt;
          &lt;/image&gt;
          &lt;/item&gt;
          &lt;item&gt;      
          &lt;paragraph&gt;pB&lt;/paragraph&gt;
          &lt;paragraph&gt;pC&lt;/paragraph&gt;
          &lt;image&gt;
              &lt;url&gt;http://www.com/image2.jpg&lt;/url&gt;
              &lt;title&gt;default image 2&lt;/title&gt;
          &lt;/image&gt;
          &lt;link target='#'&gt;linkA&lt;/link&gt;
          &lt;paragraph&gt;pD&lt;/paragraph&gt;
          &lt;link target='#'&gt;linkB&lt;/link&gt;
          &lt;/item&gt;
      &lt;/itemlist&gt;
  </code></pre>
  
  <p>If I do a foreach loop on  <code>&lt;item&gt;</code> and write values by applying the templates, such as match='paragraph' followed by match='image', then all <code>&lt;paragraph&gt;</code> will be written before the <code>&lt;image&gt;</code>, which will not result in correct output.</p>
  
  <p>Below is the output that i am expecting. Anyone has an idea how to do it?</p>
  
  <pre><code>&lt;div id="item"&gt;
      &lt;div&gt;pA&lt;/div&gt;
      &lt;img src='http://www.com/image.jpg' title='default image' /&gt;
      &lt;div&gt;pB&lt;/div&gt;
      &lt;div&gt;pC&lt;/div&gt;
      &lt;a href='#'&gt;linkA&lt;/a&gt;
      &lt;div&gt;pD&lt;/div&gt;
      &lt;img src='http://www.com/image2.jpg' title='default image 2' /&gt;
  &lt;/div&gt;
  &lt;div id="item"&gt;
      &lt;div&gt;pB&lt;/div&gt;
      &lt;div&gt;pC&lt;/div&gt;
      &lt;img src='http://www.com/image2.jpg' title='default image 2' /&gt;
      &lt;a href='#'&gt;linkA&lt;/a&gt;
      &lt;div&gt;pD&lt;/div&gt;
      &lt;a href='#'&gt;linkB&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>-----edit----
  Currently I have something like this</p>
  
  <pre><code>    &lt;xsl:for-each select="itemlist/item"&gt;
  &lt;xsl:apply-templates select="paragraph"/&gt;
  &lt;xsl:apply-templates select="link"/&gt;
  
  
    &lt;xsl:template match="paragraph"&gt;
  &lt;xsl:value-of select="." /&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="link"&gt;
  &lt;xsl:value-of select="." /&gt;
    &lt;/xsl:template&gt;
  
  
  &lt;/xsl:for-each&gt;
  </code></pre>