Ver Mensaje Individual
  #6 (permalink)  
Antiguo 13/01/2004, 12:46
Avatar de Helbira
Helbira
 
Fecha de Ingreso: octubre-2001
Ubicación: Sevilla, España
Mensajes: 1.228
Antigüedad: 22 años, 6 meses
Puntos: 5
Un Ejemplo

Te pongo un ejemplo que he encontrado (Ejemplo )

Creas un archivo xml que correspondería con tu archivo xml inicial y a partir del cual generarias otro xml:

<?xml version="1.0"?>
Código PHP:
<novedades>
    <
doc tipo="libro"/>
    <
doc tipo="revista"/>
    <
doc tipo="cdrom"/>
    <
doc tipo="cdrom"/>
</
novedades
Ahora crearías el xsl que te transforma ese xml en otro xml distinto:

Código PHP:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>
  <xsl:attribute-set name="general">
    <xsl:attribute name="doc_id"/>
    <xsl:attribute name="titulo"/>
  </xsl:attribute-set>
  <xsl:attribute-set name="libro" use-attribute-sets="general">
    <xsl:attribute name="isbn"/>
  </xsl:attribute-set>
  <xsl:attribute-set name="revista" use-attribute-sets="general">
    <xsl:attribute name="issn"/>
  </xsl:attribute-set>
  <xsl:template match="novedades">
    <xsl:element name="formulario">
    <xsl:for-each select="doc">
      <xsl:choose>
        <xsl:when test="@tipo='libro'">
          <xsl:element name="doc" use-attribute-sets="libro"/>
       </xsl:when>
       <xsl:when test="@tipo='revista'">
         <xsl:element name="doc" use-attribute-sets="revista"/>
       </xsl:when>
       <xsl:otherwise>
         <xsl:element name="doc" use-attribute-sets="general"/>
       </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
  </xsl:element>
</xsl:template>
</xsl:stylesheet>
Asignas este xsl a tu xml y abres el xml en el navegador. Et Voilá, debería sacarte por pantalla un xml como el que sigue:

Código PHP:
<?xml version="1.0" encoding="UTF-8"?>
<formulario>
    <doc doc_id="" titulo="" isbn=""/>
    <doc doc_id="" titulo="" issn=""/>
    <doc doc_id="" titulo=""/>
    <doc doc_id="" titulo=""/>
</formulario>