Difference between revisions of "Fil RSS en XML"

From Wiki
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Demo ==
 
== Demo ==
* http://code.sitegb.com/projet-rss/
+
* Demo complète : https://code.sitegb.com/projet-rss/
 +
* Les étapes : https://code.sitegb.com/projet-rss-etapes/
  
 
== Liens ==
 
== Liens ==
Line 23: Line 24:
  
 
== Exemple de code==
 
== Exemple de code==
 +
 +
=== xsl:value-of ===
 +
<syntaxhighlight lang="xml">
 +
<xsl:value-of select="rss/channel/title"/>
 +
<xsl:value-of select="enclosure/@url"/>
 +
<xsl:value-of select="description" disable-output-escaping="yes"/>
 +
</syntaxhighlight>
 +
 +
=== xsl:for-each ===
 +
<syntaxhighlight lang="xml">
 +
<xsl:for-each select="rss/channel/item">
 +
    <xsl:value-of select="position()"/>
 +
</xsl:for-each>
 +
</syntaxhighlight>
 +
 
=== XSL pour fil RSS ===
 
=== XSL pour fil RSS ===
 
 
<syntaxhighlight lang="xml">
 
<syntaxhighlight lang="xml">
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
<body>
 
<body>
 
 
<h2><xsl:value-of select="rss/channel/title"/></h2>
 
<h2><xsl:value-of select="rss/channel/title"/></h2>
 
<p><xsl:value-of select="rss/channel/lastBuildDate"/></p>
 
<p><xsl:value-of select="rss/channel/lastBuildDate"/></p>
 
 
<xsl:for-each select="rss/channel/item">
 
<xsl:for-each select="rss/channel/item">
 
   <div>
 
   <div>
Line 40: Line 53:
 
     <img><xsl:attribute name="src"><xsl:value-of select="enclosure/@url"/></xsl:attribute></img>
 
     <img><xsl:attribute name="src"><xsl:value-of select="enclosure/@url"/></xsl:attribute></img>
 
   </div>
 
   </div>
 
 
 
</xsl:for-each>
 
</xsl:for-each>
 
 
</body>
 
</body>
 
</html>
 
</html>
 +
</syntaxhighlight>
 +
 +
=== Code php pour pour XSLTProcessor ===
 +
<syntaxhighlight lang="php">
 +
<?php
 +
$xml = new DOMDocument;
 +
$xml->load('news.rss');
 +
 +
$xsl = new DOMDocument;
 +
$xsl->load('rss.xsl');
 +
 +
// Configuration du transformateur
 +
$proc = new XSLTProcessor;
 +
$proc->importStyleSheet($xsl);
 +
 +
echo $proc->transformToXML($xml);
 +
?>
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 04:00, 29 May 2020

Demo[edit]

Liens[edit]


Etapes[edit]

  • Explorer la structure XML du fil RSS
  • Ajouter un fichier XLS pour transformer le XML en HTML
    • value-of
    • boucle for-each
    • gestion des attributs HTML
    • tag XML / attribut XML
    • CData
  • Mettre en forme avec gabarit Bootstrap
  • Utilisation dynamique (vrai fil RSS) avec php
  • Navigation micro site


Exemple de code[edit]

xsl:value-of[edit]

<syntaxhighlight lang="xml"> <xsl:value-of select="rss/channel/title"/> <xsl:value-of select="enclosure/@url"/> <xsl:value-of select="description" disable-output-escaping="yes"/> </syntaxhighlight>

xsl:for-each[edit]

<syntaxhighlight lang="xml"> <xsl:for-each select="rss/channel/item">

   <xsl:value-of select="position()"/>

</xsl:for-each> </syntaxhighlight>

XSL pour fil RSS[edit]

<syntaxhighlight lang="xml"> <?xml version="1.0" encoding="UTF-8"?> <html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <body>

<xsl:value-of select="rss/channel/title"/>

<xsl:value-of select="rss/channel/lastBuildDate"/>

<xsl:for-each select="rss/channel/item">

   <xsl:value-of select="enclosure/@url"/>
<a><xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute>

<xsl:value-of select="title"/>

</a>
<xsl:value-of select="description" disable-output-escaping="yes"/>
   <img><xsl:attribute name="src"><xsl:value-of select="enclosure/@url"/></xsl:attribute></img>

</xsl:for-each> </body> </html> </syntaxhighlight>

Code php pour pour XSLTProcessor[edit]

<syntaxhighlight lang="php"> <?php $xml = new DOMDocument; $xml->load('news.rss');

$xsl = new DOMDocument; $xsl->load('rss.xsl');

// Configuration du transformateur $proc = new XSLTProcessor; $proc->importStyleSheet($xsl);

echo $proc->transformToXML($xml); ?> </syntaxhighlight>