Passaggio all'ora legale 31 marzo 2024 02:00 03:00 sposta avanti l'orologio di 1 ora (si dorme 1 ora in meno)
Questo esempio mostra come è possibile formattare un feed rss (test.xml) in html (text.htm) passando attraverso una trasformazione fatta tramite un foglio di stile xml (test.xsl).
Il file xsl mostra anche come è possibile accedere agli attributi (uso del simbolo @), come è possibile impostare degli attributi (tag xsl:attribute), come recuperare un valore (xsl:value-of) o come riferirsi in modo assoluto ad un elemento (/rss/@version) e come ciclare su un insieme di elementi (xsl:for-each).
XML: Test.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="test.xsl" ?>
<rss version="0.91">
  <channel att="aa">
    <title>Sgart.it</title>
    <link>http://www.sgart.it</link>
    <description>Un po' di tutto</description>
    <language>it-IT</language>
    <image>
      <title>www.sgart.it</title>
      <url>http://www.sgart.it/images/logos/logo.gif</url>
      <link>http://www.sgart.it</link>
    </image>

    <item>
      <title>Indent XML</title>
      <link>http://www.sgart.it/Page/default.asp?id=18&e=195</link>
      <description>Questo programma l'ho creato per indentare i file XML e renderli più leggibili (ad esempio i file di SharePoint).</description>
    </item>

    <item>
      <title>Regular Expression Search</title>
      <link>http://www.sgart.it/Page/default.asp?id=18&e=147</link>
      <description>Con questo programma è possibile eseguire delle ricerche, tramite le regular expression, all'interno di un testo o file.</description>
    </item>

    <item>
      <title>WinSMTPTest</title>
      <link>http://www.sgart.it/Page/default.asp?id=18&e=116</link>
      <description>Questo software permette automatizzare l'invio di comandi a un server SMTP (Simple Mail Transfer Protocol - RFC821).</description>
    </item>
  </channel>
</rss>

XML: Test.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
  <xsl:template match="/rss">
    <!-- i dati generali -->
    <xsl:for-each select="channel">
      <div style="width:500px; padding: 5px;">
        <table border="0" style="background-color: #FFFFE1; width:100%; border:1px solid #c0c0c0;">
          <tr>
            <td>
              <!-- il titolo -->
              <h3>
                <a target="_blank">
                  <xsl:attribute name="href">
                    <xsl:value-of select="link" />
                  </xsl:attribute>
                  <xsl:value-of select="title" />
                </a>
              </h3>
            </td>
            <td align="right" rowspan="2">
              <!-- il logo -->
              <a target="_blank">
                <xsl:attribute name="href">
                  <xsl:value-of select="link" />
                </xsl:attribute>
                <img border="0">
                  <xsl:attribute name="src">
                    <xsl:value-of select="image/url" />
                  </xsl:attribute>
                </img>
              </a>
            </td>
          </tr>
          <tr>
            <td>
              <!-- la descrizione -->
              <xsl:value-of select="description" /> 
              ( rss ver. <xsl:value-of select="/rss/@version" /> )
            </td>
          </tr>
        </table>
        <!-- le notizie -->
        <br />
        <div style="background-color: #fafafa; border: 1px solid #c0c0c0; padding: 5px;">
          <xsl:for-each select="item">
            <a target="_blank">
              <xsl:attribute name="href">
                <xsl:value-of select="link" />
              </xsl:attribute>
              <xsl:value-of select="title" />
            </a>
            <p><xsl:value-of select="description"/></p>
            <br />
          </xsl:for-each>
        </div>
      </div>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

risultato in HTML
HTML: text.htm
<div style="padding: 5px; width: 500px;">
  <table border="0" style="background-color: #FFFFE1; width:100%; border:1px solid #c0c0c0;">
    <tr>
      <td>
        <h3>
          <a href="http://www.sgart.it" target="_blank">Sgart.it</a>
        </h3>
      </td>
      <td rowspan="2" align="right">
        <a href="http://www.sgart.it" target="_blank">
          <img src="http://www.sgart.it/images/logos/logo.gif" border="0">
        </a>
      </td>
    </tr>
    <tr>
      <td>Un po' di tutto
        ( rss ver. 0.91 )
      </td>
    </tr>
  </table>
  <br>
  <div style="background-color: #fafafa; border: 1px solid #c0c0c0; padding: 5px;">
    <a href="http://www.sgart.it/Page/default.asp?id=18&e=195" target="_blank">Indent XML</a>
    <p>Questo programma l'ho creato per indentare i file XML e renderli più leggibili (ad esempio i file di SharePoint).</p>
    <br>
    <a href="http://www.sgart.it/Page/default.asp?id=18&e=147" target="_blank">Regular Expression Search</a>
    <p>Con questo programma è possibile eseguire delle ricerche, tramite le regular expression, all'interno di un testo o file.</p>
    <br>
    <a href="http://www.sgart.it/Page/default.asp?id=18&e=116" target="_blank">WinSMTPTest</a>
    <p>Questo software permette automatizzare l'invio di comandi a un server SMTP (Simple Mail Transfer Protocol - RFC821).</p>
    <br>
  </div>
</div>
che verrà così visualizzato dal browser (a parte il font e i colori)

Sgart.it

Un po' di tutto ( rss ver. 0.91 )

Indent XML

Questo programma l'ho creato per indentare i file XML e renderli più leggibili (ad esempio i file di SharePoint).


Regular Expression Search

Con questo programma è possibile eseguire delle ricerche, tramite le regular expression, all'interno di un testo o file.


WinSMTPTest

Questo software permette automatizzare l'invio di comandi a un server SMTP (Simple Mail Transfer Protocol - RFC821).


Potrebbe interessarti anche: