When parsing some an XSL XML file using docx4j, I keep receiving this error:
'The element type "img" must be terminated by the matching end-tag
"</img>". Exception Error in Docx4JException'
I have tried all sorts of combinations to solve the issue but nothing seems to work apart from putting some text in between the img tags. I don't want the text to display. Is there anything else that can be done?
This is the piece of xsl that is causing the error:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:prettyprint="http://xml.apache.org/xslt" xmlns:xalan="http://xml.apache.org/xalan" version="1.0">
   <xsl:output method="html" />
   <!-- Main entry template -->
   <xsl:template match="Email">
      <html>
         <body>
            <img width="100" height="100" src="http://thumbs.dreamstime.com/x/sun-logo-6350903.jpg" border="0" class="MyImage" />
            <div style="font-family:Verdana, Arial; font-size:9.5pt; font-weight:normal">
               <xsl:variable name="PTPTotalAmt" select="Issue_PTPTotalAmount_C" />
               <xsl:variable name="LetterDate" select="LetterDate" />
               <xsl:variable name="LtrDate" select="substring($LetterDate, 1, 11)" />
               <br>
                  <xsl:text />
               </br>
               <xsl:value-of select="Contact_Title_R" />
               <xsl:text />
               <xsl:value-of select="Contact_LastName_X" />
               <br>
                  <xsl:text />
               </br>
               <xsl:value-of select="Contact_DispAddrLine1_X" />
               <br>
                  <xsl:text />
               </br>
               <xsl:value-of select="Contact_DispAddrLine3_X" />
               <br>
                  <xsl:text />
               </br>
               <xsl:value-of select="Contact_DispAddrLine4_X" />
               <br>
                  <xsl:text />
               </br>
               <xsl:value-of select="Contact_DispAddrLine5_X" />
               <br>
                  <xsl:text />
               </br>
               <xsl:value-of select="Contact_DispAddrPostCode_X" />
               <br>
                  <xsl:text />
               </br>
               <xsl:text />
               <xsl:text />
               <xsl:value-of select="$LtrDate" />
            </div>
            <br>
               <xsl:text />
            </br>
            <br>
               <xsl:text />
            </br>
            <br>
               <xsl:text />
            </br>
            <br>
               <xsl:text />
            </br>
            <div style="font-family:Verdana, Arial; font-size:8.5pt; font-weight:normal">
               <br>
                  <xsl:text>Address Here</xsl:text>
               </br>
            </div>
         </body>
      </html>
   </xsl:template>
</xsl:stylesheet>
Change your xsl:output element to output XML:
<xsl:output method="xml" indent="yes"/>
(The indent="yes" part isn't required but will help with reading the output.)
If the xsl:output method="xml" change alone does not work, try explicitly closing the img element.  So, instead of <img/>, use <img></img>:
<img width="100" height="100" src="http://thumbs.dreamstime.com/x/sun-logo-6350903.jpg" border="0" class="MyImage"></img>
Explanation:  HTML plays fast and loose wrt end tags.  Downstream processing by docx4j wants properly terminated elements, and XSLT will generate properly terminated elements when you specify <xsl:output method="xml"/>.
If you want to add image and it is regularly asking for closing the tag you just write like this:
<img src="abc"/>
This works !! simple add the clossing tag to the Img Tag like this
<img src=""/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With