0

all. I have a really big problem i want to ask for info, please. Ive got a project in java, one of the functions of this proyect, is that have to parse some xls. Well, ive got a problem while parsing one. This is the loop who parse the xsls:

while(itera.hasNext()){
        // Creacion del transformador de SAX
            tFactory.setErrorListener(new ManejadorXSLTErrores());
            String nombrePlantilla = (String)itera.next();
            //creamos el objeto transformer
            String stream = (String)plantillas.get(nombrePlantilla);
            if((stream!= null) && (getClass()!=null) && (getClass().getResourceAsStream(stream)!=null))
                reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(stream)));
            else
                throw new ExceptionErrorARQSD(ConstantesErrorSD.ERROR_XML_TRANSFORMACION,new String[]{"Error al obtener el StreamSource: "+stream},null);
            transformer = tFactory.newTemplates(new StreamSource(reader)); 
            //se guardan en un contenedor
            contenedortransformers.putElemento(nombrePlantilla,transformer);
        }

And this is part of the xsd of my excel:

<?xml version="1.0" encoding="UTF-8"?>
                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xalan="http://xml.apache.org/xslt">

                <xsl:param name="servicio">
                    <xsl:value-of select="normalize-space(/SD/MENSAJECM/contenedorPeticionDatosComunes/codigoServicio)"/>
                </xsl:param>
        <xsl:template match="/">
                <xsl:apply-templates/>
            </xsl:template>


            <xsl:template match="SD">
                <xsl:apply-templates/>
            </xsl:template>



            <xsl:template match="MENSAJECM">
                <xsl:if test="$servicio = 'NSPLA001'">
                    <xsl:element name="MensajeSolicitud">
                        <xsl:apply-templates/>
                    </xsl:element>
                </xsl:if>
                <xsl:if test="$servicio = 'NSPLA002'">
                    <xsl:apply-templates/>
                </xsl:if>
            </xsl:template>

    <xsl:template match="contenedorPeticionDatosComunes">
            <xsl:if test="$servicio = 'NSPLA001'">
                <xsl:param name="fecha"><xsl:value-of select="normalize-space(./fecha)"/></xsl:param>
                <xsl:param name="hora"><xsl:value-of select="normalize-space(./hora)"/></xsl:param>
                <!-- Cod. Entidad U.O.R. (csbc) -->
                <xsl:attribute name="csbc">
                    <xsl:value-of select="substring(./unidadOrganizativaResponsable,1,4)"/>
                </xsl:attribute>

                <xsl:attribute name="fecha_envio">
                    <xsl:value-of select="$fecha"/>
                </xsl:attribute>

                <xsl:attribute name="oficina">
                    <xsl:value-of select="substring(./unidadOrganizativaResponsable,5,4)"/>
                </xsl:attribute>

                <xsl:attribute name="terminal">
                    <xsl:value-of select="substring(./unidadOrganizativaResponsable,11,2)"/>
                </xsl:attribute>

                <xsl:attribute name="usuario">
                    <xsl:value-of select="./usuario"/>
                </xsl:attribute>

                <xsl:attribute name="version">
                    <xsl:value-of select="1.0"/>
                </xsl:attribute>
            </xsl:if>
        </xsl:template>
</xsl:stylesheet>

This is the exception that i receive:

javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: org.xml.sax.SAXException: ¡xsl:param no está permitido en esta posición de la hoja de estilos!
javax.xml.transform.TransformerException: ¡xsl:param no está permitido en esta posición de la hoja de estilos!

Anyone can help me??? Thanks

Dekker
  • 85
  • 2
  • 10
  • I do not believe you can have an xsl:param under the xsl:if it must be a direct child of the stylesheet or the template and must be first. http://stackoverflow.com/questions/7378859/usage-of-xslt-params-xslparam-xslwith-param at least that is how I am reading it. – Rob Sep 29 '16 at 11:02
  • Rob, so in your opinion , the xsl is not correct? I didnt create this xsl. – Dekker Sep 29 '16 at 11:06

2 Answers2

1

Right so to make it work with the if in there you should use try this:

<?xml version="1.0" encoding="UTF-8"?>
                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xalan="http://xml.apache.org/xslt">

                <xsl:param name="servicio">
                    <xsl:value-of select="normalize-space(/SD/MENSAJECM/contenedorPeticionDatosComunes/codigoServicio)"/>
                </xsl:param>
        <xsl:template match="/">
                <xsl:apply-templates/>
            </xsl:template>


            <xsl:template match="SD">
                <xsl:apply-templates/>
            </xsl:template>



            <xsl:template match="MENSAJECM">
                <xsl:if test="$servicio = 'NSPLA001'">
                    <xsl:element name="MensajeSolicitud">
                        <xsl:apply-templates/>
                    </xsl:element>
                </xsl:if>
                <xsl:if test="$servicio = 'NSPLA002'">
                    <xsl:apply-templates/>
                </xsl:if>
            </xsl:template>

    <xsl:template match="contenedorPeticionDatosComunes">
            <xsl:param name="fecha"><xsl:value-of select="normalize-space(./fecha)"/></xsl:param>
            <xsl:param name="hora"><xsl:value-of select="normalize-space(./hora)"/></xsl:param>
            <xsl:if test="$servicio = 'NSPLA001'">
                <!-- Cod. Entidad U.O.R. (csbc) -->
                <xsl:attribute name="csbc">
                    <xsl:value-of select="substring(./unidadOrganizativaResponsable,1,4)"/>
                </xsl:attribute>

                <xsl:attribute name="fecha_envio">
                    <xsl:value-of select="$fecha"/>
                </xsl:attribute>

                <xsl:attribute name="oficina">
                    <xsl:value-of select="substring(./unidadOrganizativaResponsable,5,4)"/>
                </xsl:attribute>

                <xsl:attribute name="terminal">
                    <xsl:value-of select="substring(./unidadOrganizativaResponsable,11,2)"/>
                </xsl:attribute>

                <xsl:attribute name="usuario">
                    <xsl:value-of select="./usuario"/>
                </xsl:attribute>

                <xsl:attribute name="version">
                    <xsl:value-of select="1.0"/>
                </xsl:attribute>
            </xsl:if>
        </xsl:template>
</xsl:stylesheet>
Rob
  • 2,618
  • 2
  • 22
  • 29
0

Thanks Rob specially for your help, the xls is not well formed :

<xsl:template match="contenedorPeticionDatosComunes">
        <!-- <xsl:if test="$servicio = 'NSPLA001'"> -->
            <xsl:param name="fecha"><xsl:value-of select="normalize-space(./fecha)"/></xsl:param> 
            <xsl:param name="hora"><xsl:value-of select="normalize-space(./hora)"/></xsl:param>
            <!-- Cod. Entidad U.O.R. (csbc) -->
            <xsl:attribute name="csbc">
                <xsl:value-of select="substring(./unidadOrganizativaResponsable,1,4)"/>
            </xsl:attribute>
            <!-- Fecha Envío -->
            <xsl:attribute name="fecha_envio">
                <xsl:value-of select="$fecha"/>
            </xsl:attribute>
            <!-- Cod. Oficina U.O.R. -->
            <xsl:attribute name="oficina">
                <xsl:value-of select="substring(./unidadOrganizativaResponsable,5,4)"/>
            </xsl:attribute>
            <!-- Cod. Terminal U.O.R. -->
            <xsl:attribute name="terminal">
                <xsl:value-of select="substring(./unidadOrganizativaResponsable,11,2)"/>
            </xsl:attribute>
            <!-- Id Usuario -->
            <xsl:attribute name="usuario">
                <xsl:value-of select="./usuario"/>
            </xsl:attribute>
            <!-- Version -->
            <xsl:attribute name="version">
                <xsl:value-of select="1.0"/>
            </xsl:attribute>
        <!-- </xsl:if> -->
    </xsl:template>

If I comment the like this way, now, i dont recieve any error in the loop while parse the xsls.

Dekker
  • 85
  • 2
  • 10