gpt4 book ai didi

java - XSL,编译 javax.xml.transform.TransformerException 时出现问题 :

转载 作者:行者123 更新时间:2023-12-01 09:26:48 26 4
gpt4 key购买 nike

全部。我有一个非常大的问题,我想询问信息,请。我有一个java项目,这个项目的功能之一就是必须解析一些xls。好吧,我在解析时遇到了问题。这是解析 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);
}

这是我的 Excel 的 xsd 的一部分:

<?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>

这是我收到的异常:

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!

谁能帮帮我???谢谢

最佳答案

是的,为了让它与 if 一起工作,你应该使用试试这个:

<?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>

关于java - XSL,编译 javax.xml.transform.TransformerException 时出现问题 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39768334/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com