Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Problema XSL 2.0

  1. #1

    Problema XSL 2.0

    Ciao a tutti,
    sto cercando di realizzare un semplice xsl per convertire un file xml in un formato diverso.

    Il mio obbiettivo e' quello di ottenee un file con questo formato:

    Codice PHP:
    <macXimProtocol version="1.0">  
    <
    command type="response" name="executeMetrics" id="6">      
    <
    project id="?">         
    <
    metrics granularity="applicationLevel">            
    <
    metric name="a">               
        <
    stat id="tot">3</stat>            
    </
    metric>            
    <
    metric name="b">               
        <
    stat id="tot">2</stat>            
    </
    metric>   
    <
    metric name="c">               
        <
    stat id="tot">1</stat>            
    </
    metric> ... 
    Dove mostrare il tipo e il numero di "violation" uniche.


    Il file xml di partenza ha questo formato:


    Codice PHP:
    <?xml version="1.0" encoding="UTF-8"?> 
    <pmd version="4.2.5"> 
    <file name="a.java">   
       <violation rule="a" > xxx </violation>    
       <violation rule="b" > xxy </violation> 
    </file> 
    <file name="b.java">   
       <violation rule="a" > xyz </violation>    
       <violation rule="b" > abc </violation> </file> 
    <file name="b.java">   
       <violation rule="c" > xyz </violation>    
       <violation rule="a" > abc </violation> 
    </file>
    e questo e' l'XSL che utilizzo:


    Codice PHP:
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">     
    <
    xsl:output method="html" encoding="iso-8859-1" indent="no"/>          
    <
    xsl:template match="pmd">                  
    <
    macXimProtocol version="1.0">             
       <
    command type="response" name="executeMetrics" id="6">                 
      <
    project id="?">                     
      <
    metrics granularity="applicationLevel">                                                 
         <
    xsl:for-each select="distinct-values(//violation/@rule)">                             
             <
    xsl:variable name="ruleCount" select="." />                             
                  <
    metric>                                 
                       <
    xsl:attribute name="name">                                     
                            <
    xsl:value-of select="."/>                                 
                       </
    xsl:attribute>                                  
                       <
    stat id="tot">                                                                 
                             <
    xsl:value-of select="count(/pmd/file/violation[@rule=$ruleCount])"/>                                          
                      </
    stat>                                                             
                 </
    metric>                       
          </
    xsl:for-each>                     
       </
    metrics>                 
    </
    project>             
    </
    command>         
    </
    macXimProtocol>     
    </
    xsl:template
    </
    xsl:stylesheet

    L'errore e' nella riga "count(/pmd/file/violation[@rule=$ruleCount])".
    Se sostituisco il parametro della funzione count con "." restituisce sempre uno.

    Io vorrei poter risalire l'albero xml e contare invece tutte le occorrenze. QUalche idea su come farlo?

    Grazie a tutti

    Davide Taibi
    http://www.taibi.it

  2. #2
    Ciao davide.taibi,
    prova così:

    Codice PHP:
    <stat id="tot">                                                                                           <xsl:value-of select="count(../../violation[@rule=$ruleCount])"/>                               </stat
    Ciao
    Mirko Agrati
    WEB : http://mirkoagrati.110mb.com
    RSS : http://feeds.feedburner.com/MirkoAgratiArticoli

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.