title: Convert Italic XML Tags into WordML Tags II
body: <p>I'm several WEEKS old inhabiting these XSL WordML XML "worlds", and, im <em>really</em> dissapointed on the way the so called 'XSLT Processor' handle things. </p>
  
  <p>Regarding an <a href="https://stackoverflow.com/questions/234215/xml-to-wordml-using-xslt-1-0-replace-html-tags-within-xml-content-with-wordml" title="Replace XML Tags into WordML">old question</a>, the purpose is (if -we still- can call it simple) to transform Light Word XML files into well-formed WordML files. </p>
  
  <p>I'm sorry for the extended question, but i guess there is no other way to explain. </p>
  
  <p>I have the following <strong>XML document</strong>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;body&gt;
      &lt;heading&gt;
          This is the &lt;bold&gt;&lt;italic&gt;standard&lt;/italic&gt; text&lt;/bold&gt; run.
      &lt;/heading&gt;
      &lt;copyright/&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>The purpose is formatting, separately as per a WordML document, each <em>paragraph</em> and <em>character</em> style:</p>
  
  <ul>
  <li>WordML <em>paragraph</em> styles element are 'normal' and 'heading' (here only heading), and are embraced by 'w:p' tags</li>
  <li>WordML <em>character run</em> styles elements are 'italic', 'bold' and 'underline' (here only italic and bold), and are embraced by 'w:r' tags</li>
  <li>WordML <em>text</em> nodes are embraced by 'w:t' tags</li>
  </ul>
  
  <p>So, the expected <strong>WordML document</strong> output is the following:</p>
  
  <pre><code>&lt;w:wordDocument xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" 
      xml:space="preserve"&gt;
      &lt;w:body&gt;
          &lt;w:p&gt;
              &lt;w:pPr&gt;&lt;w:pStyle w:val="Heading"/&gt;&lt;/w:pPr&gt;
              &lt;w:r&gt;
                  &lt;w:t&gt;This is the &lt;/w:t&gt;
                  &lt;w:rPr&gt;&lt;w:b w:val="on"/&gt;&lt;/w:rPr&gt;
                  &lt;w:rPr&gt;&lt;w:i w:val="on"/&gt;&lt;/w:rPr&gt;
                  &lt;w:t&gt;standard &lt;/w:t&gt;
                  &lt;w:rPr&gt;&lt;w:i w:val="off"/&gt;&lt;/w:rPr&gt;
                  &lt;w:t&gt;text &lt;/w:t&gt;
                  &lt;w:rPr&gt;&lt;w:b w:val="off"/&gt;&lt;/w:rPr&gt;
                  &lt;w:t&gt;run.&lt;/w:t&gt;
              &lt;/w:r&gt;
          &lt;/w:p&gt;
      &lt;/w:body&gt;
  &lt;/w:wordDocument&gt;
  </code></pre>
  
  <p>Using the following <strong>XSL Template File</strong> (to be corrected by your feedback):</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:w="http://schemas.microsoft.com/office/word/2003/wordml"
      xml:space="preserve"&gt;
      &lt;xsl:output method="xml" indent="yes"/&gt;
  
      &lt;xsl:template match="body"&gt;
          &lt;w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" 
              xmlns="http://www.w3.org/1999/xhtml" 
              xml:space="preserve"&gt;
              &lt;w:body&gt;
                  &lt;xsl:apply-templates match="normal|heading"/&gt;
              &lt;/w:body&gt;
          &lt;/w:wordDocument&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="heading"&gt;
              &lt;w:p&gt;     
              &lt;w:pPr&gt;&lt;w:pStyle w:val="Heading"/&gt;&lt;/w:pPr&gt;
              &lt;w:r&gt;
                  &lt;xsl:apply-templates match="italic|bold"/&gt;
              &lt;/w:r&gt;
          &lt;/w:p&gt;
          &lt;xsl:apply-templates match="heading"/&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="bold"&gt;
          &lt;w:rPr&gt;&lt;w:b w:val="on"/&gt;&lt;/w:rPr&gt;
          &lt;xsl:apply-templates match="text()"/&gt;
          &lt;w:rPr&gt;&lt;w:b w:val="off"/&gt;&lt;/w:rPr&gt;
          &lt;xsl:apply-templates match="italic|bold"/&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="italic"&gt;
          &lt;w:rPr&gt;&lt;w:i w:val="on"/&gt;&lt;/w:rPr&gt;
          &lt;xsl:apply-templates match="text()"/&gt;
          &lt;w:rPr&gt;&lt;w:i w:val="off"/&gt;&lt;/w:rPr&gt;
          &lt;xsl:apply-templates match="italic|bold"/&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="text()"&gt;
          &lt;w:t&gt;&lt;xsl:value-of select="."/&gt;&lt;/w:t&gt;
      &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>They simply <em>dont work</em>, the XSLT Processor  completely omits the "match" sentence. Note the double apply-template is necessary, because there is different nesting location of templates according the type of paragraph - character content.</p>
  
  <p>The usual mistaken results is obtain this kind of content inside the <strong>WordML document</strong>:</p>
  
  <pre><code>    ...
      &lt;w:p&gt;
          &lt;w:r&gt;
              &lt;w:t&gt;run.&lt;/w:t&gt;
          &lt;/w:r&gt;
      &lt;/w:p&gt;    
  
      &lt;w:t&gt;This is &lt;/w:t&gt;
      ...
  </code></pre>
  
  <p>which is perfectly legal XML, but totally unacceptable, having a text outside any paragraph, making the WordML document corrupt. Besides, templates are logically correct, if those apply-template &amp; match would really do their proper job. </p>
  
  <p>Please, any suggestion (including throwing all these 'templates' and starting back in any standard language program) are acceptable.</p>