title: XSLT attribute node (id) cannot be created after the children of the containing element
body: <p>Typically i am doing an XSLT process over a Weblogic12 server. I kept running into this issue</p>
  
  <pre><code>net.sf.saxon.trans.DynamicError: An attribute node 
  (id) cannot be created after the children of the containing element
  </code></pre>
  
  <p>Before the migration, our team had no problems at all...</p>
  
  <p>Any idea why? i recently upgraded from BEA Weblogic3 to Oracle Enterprise Weblogic 12. Or am i missing a library?</p>
  
  <p>This is plaguing our entire team! Thanks!</p>
  
  <p>EDIT 1:</p>
  
  <p>Error points to <code>&lt;xsl:attribute name="id"&gt;</code> in <code>&lt;xsl:template name="makeErrorDiv"&gt;</code>     </p>
  
  <pre><code>&lt;td&gt;
              &lt;xsl:copy-of select="@colspan | @align | @style | @valign | @class | @id | @name"/&gt;
              &lt;xsl:if test="@colspan = '1' and $columnWidth != '' and not(@suppressColWidth='true')"&gt;&lt;xsl:attribute name="width"&gt;&lt;xsl:value-of select="$columnWidth"/&gt;&lt;/xsl:attribute&gt;&lt;/xsl:if&gt;
              &lt;xsl:if test="@rowspan != '1'"&gt;&lt;xsl:copy-of select="@rowspan"/&gt;&lt;/xsl:if&gt;
  
              &lt;xsl:if test="descendant::ErrMsg"&gt;
                  &lt;xsl:call-template name="makeErrorDiv"/&gt;
              &lt;/xsl:if&gt;
          &lt;/td&gt;
  
  
  &lt;xsl:template name="makeErrorDiv"&gt;      
          &lt;div style="display:none;"&gt;
              &lt;xsl:choose&gt;
                  &lt;xsl:when test="descendant::*[ParentId]"&gt;
                      &lt;xsl:attribute name="id"&gt;&lt;xsl:value-of select="descendant::ParentId[position() = 1]"/&gt;&lt;![CDATA[$err]]&gt;&lt;/xsl:attribute&gt;
                  &lt;/xsl:when&gt;         
                  &lt;xsl:when test="descendant::*[ErrMsg][Name]"&gt;
                      &lt;xsl:attribute name="id"&gt;&lt;xsl:value-of select="descendant::*[ErrMsg][position() = 1]/Name"/&gt;&lt;![CDATA[$err]]&gt;&lt;/xsl:attribute&gt;
                  &lt;/xsl:when&gt;
                  &lt;xsl:when test="not(descendant::*[ErrMsg])"&gt;
                      &lt;xsl:variable name="name"&gt;&lt;xsl:value-of select="descendant::*[Name][position() = 1]/Name"/&gt;&lt;/xsl:variable&gt;
                      &lt;xsl:variable name="parsed"&gt;&lt;xsl:value-of select="substring-before($name, '!')"/&gt;&lt;/xsl:variable&gt;
                      &lt;xsl:attribute name="id"&gt;&lt;!--error here! --&gt;
                          &lt;xsl:choose&gt;
                              &lt;xsl:when test="$parsed = ''"&gt;&lt;xsl:value-of select="$name"/&gt;&lt;/xsl:when&gt;
                              &lt;xsl:otherwise&gt;&lt;xsl:value-of select="$parsed"/&gt;&lt;/xsl:otherwise&gt;
                          &lt;/xsl:choose&gt;
                      &lt;xsl:text&gt;&lt;![CDATA[$err]]&gt;&lt;/xsl:text&gt;&lt;/xsl:attribute&gt;   
                  &lt;/xsl:when&gt;
                  &lt;xsl:when test="descendant::*[ErrMsg][not(Name)]"&gt;
                      &lt;xsl:variable name="name"&gt;&lt;xsl:value-of select="descendant::*[Name][position() = 1]/Name"/&gt;&lt;/xsl:variable&gt;
                      &lt;xsl:variable name="parsed"&gt;&lt;xsl:value-of select="substring-before($name, '!')"/&gt;&lt;/xsl:variable&gt;
                      &lt;xsl:attribute name="id"&gt;
                          &lt;xsl:choose&gt;
                              &lt;xsl:when test="$parsed = ''"&gt;&lt;xsl:value-of select="$name"/&gt;&lt;/xsl:when&gt;
                              &lt;xsl:otherwise&gt;&lt;xsl:value-of select="$parsed"/&gt;&lt;/xsl:otherwise&gt;
                          &lt;/xsl:choose&gt;
                      &lt;xsl:text&gt;&lt;![CDATA[$err]]&gt;&lt;/xsl:text&gt;&lt;/xsl:attribute&gt;                   
                  &lt;/xsl:when&gt;
              &lt;/xsl:choose&gt;   
              &lt;span style="color: #FF0000; font-family: Arial, Helvetica, sans-serif; font-size: 10px; font-weight: bold; text-decoration: none;"&gt;&lt;xsl:value-of select="descendant::ErrMsg[position() = 1]"/&gt;&lt;/span&gt;
          &lt;/div&gt;      
      &lt;/xsl:template&gt;
  </code></pre>
  
  <p>XML sample...not sure if it's helpful...the entire XML file is 1000+ lines</p>
  
  <pre><code>&lt;DisclosureRowColor template="OneColumn" position="8" lastPosition="30" colCount="4" color1="#F2F8FE" color2="#ffffff"&gt;
                  &lt;Cell colspan="1"&gt;
                      &lt;ListBox onchange="toggleAddressByAjax();"&gt;
                          &lt;Name&gt;APPLICATION_CUSTOMER.EMPLOYED_SINCE_MM!YLI&lt;/Name&gt;
                          &lt;Size&gt;1&lt;/Size&gt;
                          &lt;Default rtexprvalue="true"&gt;mb.getValue("APPLICATION_CUSTOMER.EMPLOYED_SINCE_MM!YLI", "A")&lt;/Default&gt;
                          &lt;Map rtexprvalue="true"&gt;mb.getGenericLookup("V_YEAR")&lt;/Map&gt;
                          &lt;ReadOnly rtexprvalue="true"&gt;mb.isReadonly(2)&lt;/ReadOnly&gt;
                      &lt;/ListBox&gt;
                      &lt;Label class="sTGBFBS"&gt;
                          &lt;Caption&gt; &amp;amp;nbsp;&amp;amp;nbsp;Jahre &lt;/Caption&gt;
                      &lt;/Label&gt;
                      &lt;ListBox onchange="toggleAddressByAjax();"&gt;
                          &lt;Name&gt;APPLICATION_CUSTOMER.EMPLOYED_SINCE_MM!MLI&lt;/Name&gt;
                          &lt;Size&gt;1&lt;/Size&gt;
                          &lt;Default rtexprvalue="true"&gt;mb.getValue("APPLICATION_CUSTOMER.EMPLOYED_SINCE_MM!MLI", "A")&lt;/Default&gt;
                          &lt;Map rtexprvalue="true"&gt;mb.getGenericLookup("V_MONTH")&lt;/Map&gt;
                          &lt;ReadOnly rtexprvalue="true"&gt;mb.isReadonly(2)&lt;/ReadOnly&gt;
                      &lt;/ListBox&gt;
                      &lt;Label class="sTGBGBS"&gt;
                          &lt;Caption&gt; &amp;amp;nbsp;&amp;amp;nbsp;Monate &lt;/Caption&gt;
                      &lt;/Label&gt;
                      &lt;ErrMsg/&gt;
                  &lt;/Cell&gt;
              &lt;/DisclosureRowColor&gt;
  </code></pre>