1 Reply Latest reply on Nov 18, 2013 9:42 PM by TPD-Opitz

    Error in Java code in XSL transformation

    3c914088-1203-4537-8f7a-faa086326006

      Hi,

       

      I am getting below error while transforming XML ( in string) using XSL.

       

      XML-22047: (Error) Invalid instantiation of 'xsl:template' in 'Alarm' context.


      I am using following function :


      public String strConv(String message, String xslfile) throws Exception {

       

              StringReader reader = new StringReader(message);

              StringWriter writer = new StringWriter();

              TransformerFactory tFactory = TransformerFactory.newInstance();

                Transformer transformer = tFactory

                      .newTransformer(new javax.xml.transform.stream.StreamSource(new File(xslfile)));

             

              transformer.transform(new javax.xml.transform.stream.StreamSource(

                      reader), new javax.xml.transform.stream.StreamResult(writer));

       

              return writer.toString();

          }

       

      Corresponding XSL portion :

       

      <xsl:template match="Alarm">
         <Alarm>
         <xsl:apply-templates select="Identifier" />
         <xsl:apply-templates select="updateSeqNum" />
         <xsl:apply-templates select="removeFlag" />
         <xsl:template match="Severity">
         <xsl:choose>
         <xsl:when test="Severity = '0' ">
         <perceivedSeverity>Clear</perceivedSeverity>
         </xsl:when>
         <xsl:when test="Severity = '1' ">
         <perceivedSeverity>Indeterminate</perceivedSeverity>
         </xsl:when>
         <xsl:when test="Severity = '2' ">
         <perceivedSeverity>Warning</perceivedSeverity>
         </xsl:when>
         <xsl:when test="Severity = '3' ">
         <perceivedSeverity>Minor</perceivedSeverity>
         </xsl:when>
         <xsl:when test="Severity = '4' ">
         <perceivedSeverity>Major</perceivedSeverity>
         </xsl:when>
         <xsl:when test="Severity = '5' ">
         <perceivedSeverity>Critical</perceivedSeverity>
         </xsl:when>
         <xsl:otherwise>
         <perceivedSeverity>
         <xsl:value-of select="Severity" />
         </perceivedSeverity>
         </xsl:otherwise>
         </xsl:choose>
         </xsl:template>

       

      Please help me to find out the error.

       

      Thanks.