Ver Mensaje Individual
  #8 (permalink)  
Antiguo 30/08/2011, 05:19
Avatar de masterpuppet
masterpuppet
Software Craftsman
 
Fecha de Ingreso: enero-2008
Ubicación: Montevideo, Uruguay
Mensajes: 3.550
Antigüedad: 16 años, 3 meses
Puntos: 845
Respuesta: como puedo hacer un conteo en xml a partir de un atributo??

Ahí te mostró andresdzphp el otro orden aunque no entiendo el xpath para algo tan sencillo, otra opción es utilizar xslt, por ejemplo si quisieras crear una tabla que liste ordenado por codparam y elemento, podrias hacer algo asi:

style.xsl
Código XML:
Ver original
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <xsl:output method="html" encoding="UTF-8"/>
  4. <xsl:template match="/">
  5. <table>
  6.  <thead>
  7.    <tr>
  8.      <th>codparam</th>
  9.      <th>element</th>
  10.    </tr>
  11.  </thead>
  12.  <tbody>
  13.    <xsl:for-each select="//evolucion">
  14.      <xsl:sort select="@codparam" />
  15.      <xsl:sort select="elemento" />
  16.    <tr>    
  17.      <td><xsl:value-of select="@codparam" /></td>  
  18.      <td><xsl:value-of select="elemento" /></td>
  19.    </tr>
  20.   </xsl:for-each>
  21.  </tbody>
  22. </table>
  23. </xsl:template>
  24. </xsl:stylesheet>


Código PHP:
Ver original
  1. $xml = DOMDocument::loadXML($xml);
  2.  
  3. $xslt = new XSLTProcessor();
  4. $xsl  = new DOMDocument();
  5. $xsl->load('style.xsl', LIBXML_NOCDATA);
  6. $xslt->importStylesheet($xsl);
  7.  
  8. echo $xslt->transformToXML($xml);

este approach tiene dos problemas, primero hay que manejar xslt, y segundo la extensión tiene que estar habilitada y no siempre es así.

Saludos.
__________________
http://es.phptherightway.com/
thats us riders :)