Scusa, ma l'avevo capito che il server non compilava l'asp sennò non chiedevo aiuto però non vedo la differenza che dici tu, il documento xml con le news di cui parli in realtà è un risultato di un asp, l'unica differenza col mio caso è che anzichè prenderlo in locale lo prende da un altro server ma penso sia irrilevante. Poi il codice dell'esempio non è client ma lato server...
Ho ancora molti dubbi su questo xml+xslt dal punto di vista praticità, esempio voglio costruire una rappresentazione dinamica dello scheletro in xslt, in base alla query costruisco l'xml dinamicamente tramite asp ma poi mi blocca l'xslt. Non riesco a (o non si può) scrivere il nome del tag (intestazione della colonna) e a ciclare per tutti i sotto tag, simulando i campi di un record. Per ovviare a questo includo un file xslt costruito sempre dal famoso getxml.asp:
codice:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Response.expires = 0
'**************************************
'*** PARTE DI ESTRAZIONE DAL DATABASE
'**************************************
Dim RS1, Conn1, sSQL, sOutXml, sOutXsl
Dim ind
sOutXml = ""
Set Conn1 = Server.CreateObject("ADODB.Connection")
Conn1.open(dsnHostMS)
sSQL = Request("query")
if len(sSQL) = 0 then
sSQL = "SELECT TOP 3 id_polizza, num_polizza, num_proposta, cod_stato FROM TB_POLIZZA"
end if
Set RS1 = Conn1.Execute(sSQL)
If Not Rs1.EOF Or Not Rs1.BOF Then
sOutXml = "<?xml version=" & chr(34) & "1.0" & chr(34) & " encoding=" & chr(34) & "UTF-8" & chr(34) & "?>" & VbCrLf
sOutXml = sOutXml & "<RETQUERY>" & VbCrLf
Do Until Rs1.EOF
sOutXml = sOutXml & VbTab & "<RECORD>" & VbCrLf
For ind = 0 to Rs1.Fields.Count - 1
sOutXml = sOutXml & VbTab & VbTab & "<" & Rs1.Fields(ind).name & ">"
sOutXml = sOutXml & Rs1.Fields(ind).value
sOutXml = sOutXml & "</" & Rs1.Fields(ind).name & ">" & VbCrLf
'Response.Write = VbTab & VbTab & "<" & Rs1.Fields(ind).name & ">" & Rs1.Fields(ind).value & "</" & Rs1.Fields(ind).name & ">" & VbCrLf
Next
sOutXml = sOutXml & VbTab & "</RECORD>" & VbCrLf
Rs1.MoveNext
Loop
sOutXml = sOutXml & "</RETQUERY>" & VbCrLf
End If
'*** PREPARAZIONE SCRITTURA FILES
Dim MyFile
Dim fso ' FileSystemObject
Dim TSO ' TextStreamObject
Const ForWriting = 2
Const Create = True
Set fso = CreateObject("Scripting.FileSystemObject")
'**************************************
'*** PARTE DI SCRITTURA FILE XML
'**************************************
MyFile = Server.MapPath("temp.xml")
Set TSO = fso.OpenTextFile(MyFile, ForWriting, Create)
TSO.write sOutXml
TSO.close
Set TSO = Nothing
'**************************************
'*** SCRITTURA FILE XSLT (incluso nel principale)
'**************************************
Rs1.MoveFirst
sOutXsl = ""
sOutXsl = sOutXsl & "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?>" & VbCrLf
sOutXsl = sOutXsl & "<xsl:stylesheet version=" & Chr(34) & "1.0" & Chr(34) & " xmlns:xsl=" & Chr(34) & "http://www.w3.org/1999/XSL/Transform" & Chr(34) & " xmlns=" & Chr(34) & "http://www.w3.org/1999/xhtml" & Chr(34) & ">" & VbCrLf
sOutXsl = sOutXsl & "<xsl:template name=" & Chr(34) & "mod_record_dynamic_table" & Chr(34) & ">" & VbCrLf
'sOutXsl = sOutXsl & "<div id=" & Chr(34) & "record" & Chr(34) & ">" & VbCrLf
'
sOutXsl = sOutXsl & "<table>" & VbCrLf
sOutXsl = sOutXsl & "<TH>N.</TH>" & VbCrLf
For Ind = 0 to Rs1.Fields.Count - 1
sOutXsl = sOutXsl & "<TH>" & Rs1.Fields(Ind).Name & "</TH>" & VbCrLf
Next
'
sOutXsl = sOutXsl & "<xsl:for-each select=" & Chr(34) & "//RECORD" & Chr(34) & ">" & VbCrLf
'
sOutXsl = sOutXsl & "<xsl:sort data-type=" & Chr(34) & "text" & Chr(34) & " select=" & Chr(34) & "num_polizza" & Chr(34) & " order=" & Chr(34) & "ascending" & Chr(34) & "/>" & VbCrLf
'
sOutXsl = sOutXsl & "<tr>" & VbCrLf
'recordgrey e recordwhite sono due classi del css per differenziare il colore della riga di output della tabella.
sOutXsl = sOutXsl & " <xsl:choose>" & VbCrLf
sOutXsl = sOutXsl & " <xsl:when test=" & Chr(34) & "position() mod 2 = 0" & Chr(34) & ">" & VbCrLf
sOutXsl = sOutXsl & " <xsl:attribute name=" & Chr(34) & "class" & Chr(34) & ">recordgrey</xsl:attribute>" & VbCrLf
sOutXsl = sOutXsl & " </xsl:when>" & VbCrLf
sOutXsl = sOutXsl & " <xsl:otherwise>" & VbCrLf
sOutXsl = sOutXsl & " <xsl:attribute name=" & Chr(34) & "class" & Chr(34) & ">recordwhite</xsl:attribute>" & VbCrLf
sOutXsl = sOutXsl & " </xsl:otherwise>" & VbCrLf
sOutXsl = sOutXsl & " </xsl:choose>" & VbCrLf
sOutXsl = sOutXsl & " <td><xsl:value-of select=" & Chr(34) & "position()" & Chr(34) & " /></td>" & VbCrLf
For Ind = 0 to Rs1.Fields.Count - 1
Select Case Rs1.Fields(Ind).Name
Case "num_polizza"
sOutXsl = sOutXsl & " <td><xsl:value-of select=" & Chr(34) & Rs1.Fields(Ind).Name & Chr(34) & "/></td>" & VbCrLf
Case else
sOutXsl = sOutXsl & " <td><xsl:value-of select=" & Chr(34) & Rs1.Fields(Ind).Name & Chr(34) & " /></td>" & VbCrLf
End Select
Next
sOutXsl = sOutXsl & "</tr>" & VbCrLf
sOutXsl = sOutXsl & "</xsl:for-each>" & VbCrLf
sOutXsl = sOutXsl & "</table>" & VbCrLf
'sOutXsl = sOutXsl & "</div>" & VbCrLf
sOutXsl = sOutXsl & "</xsl:template>" & VbCrLf
sOutXsl = sOutXsl & "</xsl:stylesheet>" & VbCrLf
MyFile = Server.MapPath("temp.xslt")
Set TSO = fso.OpenTextFile(MyFile, ForWriting, Create)
TSO.write sOutXsl
TSO.close
'*** DISTRUZIONE OGGETTI
Rs1.Close
Set Rs1 = Nothing
Conn1.Close
Set Conn1 = Nothing
Set TSO = Nothing
Set fso = Nothing
'Si richiama la pagina che effettua la trasformazione tra temp.xml e main.xslt(che include temp.xslt)
Response.Redirect ("xtransform.asp?" & Request.QueryString)
%>
xtransform.asp trasforma temp.xml con main.xslt, il mio scheletro fisso che include quello dinamico
codice:
<xsl:include href="temp.xslt"/>
e lo richiamo così:
codice:
<div id="record">
<xsl:call-template name="mod_record_dynamic_table" />
</div>
per comodità mia la div l'ho lasciata fuori.
Ho testato il tutto e funziona ma ho dubbi su come potrebbe comportarsi con molte richieste, probabilmente bisognerà eliminare la creazione dei file e fare la trasformazione direttamente in getxml.asp... mah!