Visualizzazione dei risultati da 1 a 9 su 9
  1. #1
    Utente di HTML.it L'avatar di Galex
    Registrato dal
    Aug 2002
    Messaggi
    667

    ORDINARE contenuto NODO XML

    ciao

    qualcuno sa dirmi,e come,se è possibile ordinare in base al contenuto un certo numero di nodi di un file XML???


    ho fatto una ricerca x vedere se se ne era già parlato,ho trovato questo:

    "non puoi farlo con DOM (o meglio è un casino), ti conviene prima trasformare il tuo XML in un altro XML con XSL utilizzando il namespace xsl:sort che te lo ordina a tuo piacimento, poi avendolo già ordinato ne fai quello che vuoi. "

    che vuol dire?qualcuno sa spiegarmi un pò più di +?

  2. #2
    Utente di HTML.it L'avatar di Corwin
    Registrato dal
    Jan 2002
    Messaggi
    584
    Diciamo che hai un file xml:

    codice:
    <?xml version="1.0" encoding="UTF-8"?>
    <radice>
     <nodo>
       <aa>ccc</aa>
       <bb>5</bb>
     </nodo>
     <nodo>
       <aa>aaa</aa>
       <bb>1</bb>
     </nodo>
     <nodo>
       <aa>bbb</aa>
       <bb>3</bb>
     </nodo>
    </radice>
    Per ordinare il file in base al contenuto di <aa> dovrai fare un foglio xsl di questo tipo

    codice:
    <?xml-stylesheet type="text/xml"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:output method="xml" encoding="UTF-8"/>
    <xsl:template match="/">
    <radice>
    <xsl:apply-templates select="radice"/>
    </radice>
    </xsl:template>
    
    <xsl:template match="radice">
    <xsl:apply-templates select="nodo">
    <xsl:sort select="aa" data-type="text" order="ascending"/>
    </xsl:apply-templates>
    </xsl:template>
    <xsl:template match="nodo">
    <nodo>
    <aa>
    <xsl:value-of select="aa"/>
    </aa>
    <bb>
    <xsl:value-of select="bb"/>
    </bb>
    </nodo>
    </xsl:template>
    </xsl:stylesheet>
    e per concludere una pagina asp che fa la trasformazione:
    codice:
    Set XML = Server.CreateObject("MSXML2.DOMDocument") 
    Set XSL = Server.CreateObject("MSXML2.DOMDocument") 
    Set RES = Server.CreateObject("MSXML2.DOMDocument") 
    
    XML.async = false 
    XML.load(Server.MapPath("filexml.xml")) 
    XSL.async = false 
    XSL.load(Server.MapPath("filexsl.xsl")) 
    RES.async = false
    
    XML.transformNodeToObject XSL,RES
    a questo punto RES contiene il documento xml ordinato.
    I don't wanna have to shout it out / I don't want my hair to fall out
    I don't wanna be filled with doubt / I don't wanna be a good boy scout
    I don't wanna have to learn to count / I don't wanna have the biggest amount
    I don't wanna grow up

  3. #3
    Utente di HTML.it L'avatar di Galex
    Registrato dal
    Aug 2002
    Messaggi
    667
    mmm...domani provo xchè non ho mai fatto una cosa del genere

    intanto ti ringrazio!


  4. #4
    Utente di HTML.it L'avatar di Corwin
    Registrato dal
    Jan 2002
    Messaggi
    584
    In ogni caso ti conviene provare a chiedere sul forum di xml se esiste un modo migliore di duplicare i nodi nel foglio xsl dopo averli ordinati... se il file è complesso come l'ho messo giù io non è certamente il massimo....
    I don't wanna have to shout it out / I don't want my hair to fall out
    I don't wanna be filled with doubt / I don't wanna be a good boy scout
    I don't wanna have to learn to count / I don't wanna have the biggest amount
    I don't wanna grow up

  5. #5
    Utente di HTML.it L'avatar di Galex
    Registrato dal
    Aug 2002
    Messaggi
    667
    mmm,e se invece io non volessi ordinare il file al momento di andarlo a leggerlo,ma invece volessi farlo nel momento in cui vado ad aggiungere un nodo?

    cioè io ho un file XML è + o meno così:

    <matricole>
    <matricola id="1">11111</matricola>
    <matricola id="2">11112</matricola>
    <matricola id="3">11113</matricola>
    <matricola id="4">11114</matricola>
    <matricola id="5">11116</matricola>
    </matricole>


    ora io voglio andare a mettere un nodo con matricola 11115 tra la xxxx4 e la xxxx6, si può fare un append in un punto preciso?e avrebeb senso?

  6. #6
    Utente di HTML.it L'avatar di Corwin
    Registrato dal
    Jan 2002
    Messaggi
    584
    Beh, si potrebbe fare... il punto è: nell'id cosa ci metti ? 4.5 ?
    I don't wanna have to shout it out / I don't want my hair to fall out
    I don't wanna be filled with doubt / I don't wanna be a good boy scout
    I don't wanna have to learn to count / I don't wanna have the biggest amount
    I don't wanna grow up

  7. #7
    Utente di HTML.it L'avatar di Galex
    Registrato dal
    Aug 2002
    Messaggi
    667
    l'id è un campo ID che corrisponde al record su di un database

  8. #8
    Utente di HTML.it L'avatar di Corwin
    Registrato dal
    Jan 2002
    Messaggi
    584
    <%
    Matricola = "11115"
    id = "6"

    Set objXML = Server.CreateObject("Microsoft.XMLDOM")
    objXML.async = False
    objXML.load Server.MapPath("file.xml")

    Set NewNodo = objXML.CreateElement("matricola")
    NewNodo.Text = Matricola
    NewNodo.SetAttribute "id",id

    Set Root = objXML.documentElement
    Set ListaNodi = Root.ChildNodes
    For i = 0 To (ListaNodi.length - 1)
    If ListaNodi(i).Text > Matricola Then
    Root.InsertBefore newNodo, ListaNodi(i)
    Exit For
    end if
    Next
    If i=(ListaNodi.Length) then
    Root.AppendChild newNodo
    end if
    objXML.Save Server.MapPath("file.xml")

    %>
    I don't wanna have to shout it out / I don't want my hair to fall out
    I don't wanna be filled with doubt / I don't wanna be a good boy scout
    I don't wanna have to learn to count / I don't wanna have the biggest amount
    I don't wanna grow up

  9. #9
    Utente di HTML.it L'avatar di Galex
    Registrato dal
    Aug 2002
    Messaggi
    667
    grande,penso che così risolvo il mio prblema.
    Ti ringrazio,domani provo

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 © 2025 vBulletin Solutions, Inc. All rights reserved.