简体   繁体   中英

Why won't my xml and xslt link if the conditions are met?

as it says in the title my xml does not read my xslt, I want to make a list taking the "first name" and "last name" but it doesn't work for me, I don't know if I'm making a mistake when putting the name or maybe I'm not doing well, saying that everything is stored in the same folder so there should be no problem but there is. I am attaching my xml and xslt to see if I am getting something wrong:

xml name "comunidad":

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="datos.xslt"?>
<comunidad fecha_actualizacion="2020-01-20T08:00:00">
    <propietarios>
        <propietario id="JMMM" apellidos="Mendoza Martínez" nombre="José Manuel" alcorriente="true" />
        <propietario id="AFGL" apellidos="Gálvez Lorente" nombre="Ana Francisca" alcorriente="true" />
        <propietario id="CNAA" apellidos="Casas Nuevas" nombre="Alfredo Arturo" alcorriente="true" />
        <propietario id="CEGL" apellidos="Gómez López" nombre="Cristina Elena" alcorriente="true" />
        <propietario id="GRNC" apellidos="Navas Conesa" nombre="Gregorio Rodrigo" />
        <propietario id="IPUL" apellidos="Usillos Liarte" nombre="Ignacio Patricio" />
    </propietarios>
    <propiedades>
        <propiedad id="C01" tipo="vivienda120" contacto="CNAA">
            <participacion propietario="CNAA" porcentaje="50" />
            <participacion propietario="AFGL" porcentaje="50" />
        </propiedad>
        <propiedad id="C02" tipo="vivienda90">
            <participacion propietario="GRNC" porcentaje="100" />
        </propiedad>
        <propiedad id="C03" tipo="vivienda90" contacto="CEGL">
            <participacion propietario="IPUL" porcentaje="50" />
            <participacion propietario="CEGL" porcentaje="50" />
        </propiedad>
        <propiedad id="C04" tipo="vivienda150">
            <participacion propietario="JMMM" porcentaje="100" />
        </propiedad>
        <propiedad id="G01" tipo="garaje" contacto="CNAA">
            <participacion propietario="CNAA" porcentaje="50" />
            <participacion propietario="AFGL" porcentaje="50" />
        </propiedad>
        <propiedad id="G02" tipo="garaje">
            <participacion propietario="JMMM" porcentaje="100" />
        </propiedad>
    </propiedades>
    <cuotas>
        <cuota tipo="vivienda90" valor="35.0" />
        <cuota tipo="vivienda120" valor="45.0" />
        <cuota tipo="vivienda150" valor="50.0" />
        <cuota tipo="garaje" valor="15.0" />
    </cuotas>
    <derramas>
        <derrama id="D001" valor="20.0" asunto="Arreglos fachada" desde="2019-10-01" hasta="2020-09-01">
        Se ha procedido a restaurar la fachada completa, usando mortero monocapa,
        según acuerdo de junta ordinaria de la fecha 15/07/2019.
        </derrama>
    </derramas>
</comunidad>

and xslt called datos:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="/">

<html>
    <body>
        <h3>Listado de ropietarios al corriente de pago</h3>
        <xsl:for-each select="/comunidad/propietarios/propietario[@alcorriente]">
            <ul>
                <li><xsl:value-of select="@nombre"></li>
                <li><xsl:value-of select="@apellidos"></li>
            </ul>
        </xsl:for-each>
    </body>
</html>
</xsl:template>
</xsl:stylesheet>

You are not closing the xsl:value-of elements properly, and the reason you are not getting a useful error message is perhaps because you are running this in a browser.

Corrected XSLT Stylesheet

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="/">

<html>
    <body>
        <h3>Listado de ropietarios al corriente de pago</h3>
        <xsl:for-each select="/comunidad/propietarios/propietario[@alcorriente]">
            <ul>
                <li><xsl:value-of select="@nombre"/></li>
                <li><xsl:value-of select="@apellidos"/></li>
            </ul>
        </xsl:for-each>
    </body>
</html>
</xsl:template>
</xsl:stylesheet>

HTML Output

<html>
   <body>
      <h3>Listado de ropietarios al corriente de pago</h3>
      <ul>
         <li>José Manuel</li>
         <li>Mendoza Martínez</li>
      </ul>
      <ul>
         <li>Ana Francisca</li>
         <li>Gálvez Lorente</li>
      </ul>
      <ul>
         <li>Alfredo Arturo</li>
         <li>Casas Nuevas</li>
      </ul>
      <ul>
         <li>Cristina Elena</li>
         <li>Gómez López</li>
      </ul>
   </body>
</html>

Additional tip: if your browser does not display the desired results, run the same transformation elsewhere, for instance with this online tool here: http://xsltransform.net/ . In many cases, such a tool will display a more helpful error message.


If that does not solve your problem then perhaps the XSLT file has a different name or is not available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM