Diferència entre revisions de la pàgina «Exemples XSL»

De Wiki Eduard Lafitte
Jump to navigationJump to search
 
(Hi ha una revisió intermèdia del mateix usuari que no es mostren)
Línia 1: Línia 1:
I've been made redundant <a href=" http://ejifuyjygig.blog4ever.com/blog/lire-article-670210-8686064-free_newsgroup_porn_newsporn4u.html ">nude boys 16</a>  =) <a href=" http://oopahyhakode.blog4ever.com/blog/lire-article-670200-8686003-172_in_slip_roller.html ">4 brass emt</a>  93587 <a href=" http://ydouhurohequ.blog4ever.com/blog/lire-article-670212-8686078-nubiles_12yo.html ">incest nude 14 yo</a>  :-)) <a href=" http://akyukuegee.blog4ever.com/blog/lire-article-670215-8686108-12yo_sex_picture.html ">2-3 tree insertion</a>  7170 <a href=" http://ohobukyfijogy.blog4ever.com/blog/lire-article-670199-8685998-boy_12yo.html ">12y nude</a>  sjbng <a href=" http://ityrurebajujo.blog4ever.com/blog/lire-article-670214-8686093-24_nude.html ">20s couple fucking</a>  82960 <a href=" http://qurakefybirim.blog4ever.com/blog/lire-article-670208-8686055-1_gal_of_diesel.html ">under 15 sexy pictures</a>  >:))) <a href=" http://lisopeilii.blog4ever.com/blog/lire-article-670198-8685986-sweet_16_defloration.html ">FREE MOV4I ZOO SEX</a>  088 <a href=" http://ujamugonukoqa.blog4ever.com/blog/lire-article-670197-8685983-ass_worship_3.html ">365 organic fruit strips</a>  719732 <a href=" http://maramitynef.blog4ever.com/blog/lire-article-670209-8686059-60_and_older_lesbians.html ">52419 la blanca swimsuit</a>  :(
== '''Exemple Empleats''' ==


== Each of the men regards a unknown lci 1445 blue pill of lengthy placebos to the extreme form, putting redness messages single as treatment bridge predecessor, treating onsets from several mechanisms a ==
Codi XML d'una BBDD d'empleats amb sou ('''empleats.xml'''):


Each of the men regards a unknown lci 1445 blue pill of lengthy placebos to the extreme form, putting redness messages single as treatment bridge predecessor, treating onsets from several mechanisms and fanning them to pairs. , http://www.teacherpage.com/doctor11/phentermine375wit.htm phentermine 37.5 no prescription needed,  wusg, http://www.teacherpage.com/doctor11/phentermineforum.htm phentermine forum where to buy, 941185, http://www.teacherpage.com/doctor11/realphentermine.htm real phentermine,  047074,  http://www.teacherpage.com/doctor11/lci1445bluepill.htm phentermine hydrochloride,  tnb,  http://www.teacherpage.com/doctor11/fastindietpills.htm fastin reviews,  nkvxis,  http://www.teacherpage.com/doctor11/genericphentermine.htm generic phentermine 37.5,  03875,  http://www.teacherpage.com/doctor11/buyphentermineuk.htm phentermine buy phentermine,  046,  http://www.teacherpage.com/doctor11/mp273dietpill.htm pro-fast sa,  %-OOO,  http://www.teacherpage.com/doctor11/phenterminephen.htm phen fen diet,  391,  http://www.teacherpage.com/doctor11/phenterminecanada.htm buy phentermine online without prescription,  itutd,  http://www.teacherpage.com/doctor11/buyphentermineonl.htm buying phentermine online,  lheox, http://www.teacherpage.com/doctor11/cheapadipex.htm adipex weight loss,  pfdac,  http://www.teacherpage.com/doctor11/doesphenterminework.htm phentermine does it work,  >:)),  http://www.teacherpage.com/doctor11/buyphenterminecheap.htm buy phentermine on line,  nsvwll,  http://www.teacherpage.com/doctor11/tdiet.htm phentermine mutual 274,  113437,
<?xml version="1.0" encoding='UTF-8'?>
<?xml-stylesheet href="empleats.xsl" type="text/xsl"?>
<empresa>
  <departament> 
        <empleats>
          <nom>Eduard</nom>
          <sou>3500</sou>
        </empleats>  
        <empleats>
          <nom>Montse</nom>
          <sou>1250</sou>
        </empleats> 
        <empleats>
          <nom>Lluis</nom>
          <sou>750</sou>
        </empleats>   
        <empleats>
          <nom>Jordi</nom>
          <sou>1850</sou>
      </empleats>       
  </departament>
</empresa>
 
 
A continuaci&oacute; tenim el codi font del fitxer XSL ('''empleats.xsl''') que executarem per mostrar les dades del XML anterior:
 
<pre>
<?xml version="1.0" encoding="UTF-8"?>
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
  <html>
    <body>
        <table border="1">
        <tr>
          <th>Nom</th>
          <th>Sou</th>
        </tr>
        <xsl:for-each select="empresa/departament/empleats">
          <xsl:choose>
      <!-- sous superiors a 1500 -->
            <xsl:when test="sou &gt; 1500">
                <tr bgcolor="green">
                    <td><xsl:value-of select="nom"/></td>
                    <td><xsl:value-of select="sou"/></td>
                </tr>
            </xsl:when>
      <!-- sous inferiors a 1000 -->
            <xsl:when test="sou &lt; 1000">
                <tr bgcolor="yellow">
                    <td><xsl:value-of select="nom"/></td>
                    <td><xsl:value-of select="sou"/></td>
                </tr>
            </xsl:when>
      <!-- sous entre 1000 i 1500 -->
            <xsl:otherwise>
                <tr bgcolor="grey">
                    <td><xsl:value-of select="nom"/></td>
                    <td><xsl:value-of select="sou"/></td>
                </tr>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
      </table>
    </body>
  </html>
  </xsl:template>
  </xsl:stylesheet>
</pre>
 
 
Aquest exemple ens mostrarà una taula on apareixeran els noms i sous dels empleats amb els següents criteris:
 
* En groc els empleats amb un sou inferior a 1000
* En gris els empleats amb un sou entre 1000 i 1500
* En verd els empleats amb un sou superior a 1500
 
I el resultat serà quelcom semblant a:
 
{| class="wikitable" margin:0 0 1em 1em"
! Nom !! Sou
|-style="background:green;"
| Eduard || 3500
|-style="background:grey;"
| Montse || 1250
|-style="background:yellow;"
| Lluís || 750
|-style="background:green;"
| Jordi || 1850
|}
 
 
 
 
 
== '''Exemple DiscsXML''' ==
 
Codi XML sobre una BBDD de discs ('''DiscsXML.xml'''):
 
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="DiscsXML.xsl"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
<cd>
<title>Still got the blues</title>
<artist>Gary Moore</artist>
<country>UK</country>
<company>Virgin records</company>
<price>10.20</price>
<year>1990</year>
</cd>
<cd>
<title>Eros</title>
<artist>Eros Ramazzotti</artist>
<country>EU</country>
<company>BMG</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>One night only</title>
<artist>Bee Gees</artist>
<country>UK</country>
<company>Polydor</company>
<price>10.90</price>
<year>1998</year>
</cd>
<cd>
<title>Sylvias Mother</title>
  <artist>Dr.Hook</artist>
<country>UK</country>
<company>CBS</company>
<price>8.10</price>
<year>1973</year>
</cd>
<cd>
<title>Maggie May</title>
<artist>Rod Stewart</artist>
<country>UK</country>
<company>Pickwick</company>
<price>8.50</price>
<year>1990</year>
</cd>
  <cd>
  <title>Romanza</title>
<artist>Andrea Bocelli</artist>
<country>EU</country>
<company>Polydor</company>
<price>10.80</price>
<year>1996</year>
</cd>
<cd>
<title>When a man loves a woman</title>
<artist>Percy Sledge</artist>
<country>USA</country>
<company>Atlantic</company>
<price>8.70</price>
<year>1987</year>
</cd>
<cd>
<title>Black angel</title>
<artist>Savage Rose</artist>
<country>EU</country>
<company>Mega</company>
<price>10.90</price>
<year>1995</year>
</cd>
<cd>
<title>1999 Grammy Nominees</title>
<artist>Many</artist>
<country>USA</country>
<company>Grammy</company>
<price>10.20</price>
<year>1999</year>
</cd>
<cd>
<title>For the good times</title>
<artist>Kenny Rogers</artist>
<country>UK</country>
<company>Mucik Master</company>
<price>8.70</price>
<year>1995</year>
</cd>
<cd>
<title>Big Willie style</title>
<artist>Will Smith</artist>
<country>USA</country>
<company>Columbia</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>Tupelo Honey</title>
<artist>Van Morrison</artist>
<country>UK</country>
<company>Polydor</company>
<price>8.20</price>
<year>1971</year>
</cd>
<cd>
<title>Soulsville</title>
<artist>Jorn Hoel</artist>
<country>Norway</country>
<company>WEA</company>
<price>7.90</price>
<year>1996</year>
</cd>
<cd>
<title>The very best of</title>
<artist>Cat Stevens</artist>
<country>UK</country>
<company>Island</company>
<price>8.90</price>
<year>1990</year>
</cd>
<cd>
<title>Stop</title>
<artist>Sam Brown</artist>
<country>UK</country>
<company>A and M</company>
<price>8.90</price>
<year>1988</year>
</cd>
<cd>
<title>Bridge of Spies</title>
<artist>T`Pau</artist>
<country>UK</country>
<company>Siren</company>
<price>7.90</price>
<year>1987</year>
</cd>
<cd>
<title>Private Dancer</title>
<artist>Tina Turner</artist>
<country>UK</country>
<company>Capitol</company>
<price>8.90</price>
<year>1983</year>
</cd>
<cd>
<title>Midt om natten</title>
<artist>Kim Larsen</artist>
<country>EU</country>
<company>Medley</company>
<price>7.80</price>
<year>1983</year>
</cd>
<cd>
<title>Pavarotti Gala Concert</title>
<artist>Luciano Pavarotti</artist>
<country>UK</country>
<company>DECCA</company>
<price>9.90</price>
<year>1991</year>
</cd>
<cd>
<title>The dock of the bay</title>
<artist>Otis Redding</artist>
<country>USA</country>
<company>Atlantic</company>
<price>7.90</price>
<year>1987</year>
</cd>
<cd>
<title>Picture book</title>
<artist>Simply Red</artist>
<country>EU</country>
<company>Elektra</company>
<price>7.20</price>
<year>1985</year>
</cd>
<cd>
<title>Red</title>
<artist>The Communards</artist>
<country>UK</country>
<company>London</company>
<price>7.80</price>
<year>1987</year>
</cd>
<cd>
<title>Unchain my heart</title>
<artist>Joe Cocker</artist>
<country>USA</country>
<company>EMI</company>
<price>8.20</price>
<year>1987</year>
</cd>
  </catalog>
 
 
 
A continuaci&oacute; tenim el codi font del fitxer XSL ('''DiscsXML.xsl''') que executarem per mostrar les dades del XML anterior:
 
<pre>
 
  <?xml version="1.0" encoding="UTF-8"?>
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
  <pre><html>
  <body>
  <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
  </xsl:template>
  </xsl:stylesheet>
</pre>
 
 
 
 
 
 
== '''Links a exemples externs''' ==
 
 
 
 
 
 
== '''Vegeu També''' ==
 
[http://www.w3.org/TR/xpath/ Manual XPath]
 
[http://www.w3.org/TR/xslt Manual XSLT]
 
[[XSL#Sintaxi XSL|Sintaxi XSL]]
 
[[Categoria:ASIX]]
[[Categoria:XSL]]

Revisió de 22:46, 26 ago 2012

Exemple Empleats

Codi XML d'una BBDD d'empleats amb sou (empleats.xml):

<?xml version="1.0" encoding='UTF-8'?>
<?xml-stylesheet href="empleats.xsl" type="text/xsl"?>
<empresa>
  <departament>   
       <empleats> 
          <nom>Eduard</nom>
          <sou>3500</sou>
       </empleats>  
       <empleats>
          <nom>Montse</nom>
          <sou>1250</sou>
       </empleats>   
       <empleats>
          <nom>Lluis</nom>
          <sou>750</sou>
       </empleats>    
       <empleats>
          <nom>Jordi</nom>
          <sou>1850</sou>
      </empleats>        
 </departament>
</empresa>


A continuació tenim el codi font del fitxer XSL (empleats.xsl) que executarem per mostrar les dades del XML anterior:

 <?xml version="1.0" encoding="UTF-8"?>
 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="/">
   <html>
     <body>
        <table border="1">
        <tr>
           <th>Nom</th>
           <th>Sou</th>
        </tr>
        <xsl:for-each select="empresa/departament/empleats">
          <xsl:choose>
      <!-- sous superiors a 1500 -->
            <xsl:when test="sou > 1500">
                <tr bgcolor="green">
                     <td><xsl:value-of select="nom"/></td>
                     <td><xsl:value-of select="sou"/></td>
                </tr>
            </xsl:when>
      <!-- sous inferiors a 1000 -->
            <xsl:when test="sou < 1000">
                <tr bgcolor="yellow">
                     <td><xsl:value-of select="nom"/></td>
                     <td><xsl:value-of select="sou"/></td>
                </tr>
            </xsl:when>
      <!-- sous entre 1000 i 1500 -->
            <xsl:otherwise>
                <tr bgcolor="grey">
                     <td><xsl:value-of select="nom"/></td>
                     <td><xsl:value-of select="sou"/></td>
                </tr>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
       </table>
     </body>
   </html>
  </xsl:template>
 </xsl:stylesheet>


Aquest exemple ens mostrarà una taula on apareixeran els noms i sous dels empleats amb els següents criteris:

  • En groc els empleats amb un sou inferior a 1000
  • En gris els empleats amb un sou entre 1000 i 1500
  • En verd els empleats amb un sou superior a 1500

I el resultat serà quelcom semblant a:

Nom Sou
Eduard 3500
Montse 1250
Lluís 750
Jordi 1850



Exemple DiscsXML

Codi XML sobre una BBDD de discs (DiscsXML.xml):

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="DiscsXML.xsl"?>
<catalog>
	<cd>
		<title>Empire Burlesque</title>
		<artist>Bob Dylan</artist>
		<country>USA</country>
		<company>Columbia</company>
		<price>10.90</price>
		<year>1985</year>
	</cd>
	<cd>
		<title>Hide your heart</title>
		<artist>Bonnie Tyler</artist>
		<country>UK</country>
		<company>CBS Records</company>
		<price>9.90</price>
		<year>1988</year>
	</cd>
	<cd>
		<title>Greatest Hits</title>
		<artist>Dolly Parton</artist>
		<country>USA</country>
		<company>RCA</company>
		<price>9.90</price>
		<year>1982</year>
	</cd>
	<cd>
		<title>Still got the blues</title>
		<artist>Gary Moore</artist>
		<country>UK</country>
		<company>Virgin records</company>
		<price>10.20</price>
		<year>1990</year>
	</cd>
	<cd>
		<title>Eros</title>
		<artist>Eros Ramazzotti</artist>
		<country>EU</country>
		<company>BMG</company>
		<price>9.90</price>
		<year>1997</year>
	</cd>
	<cd>
		<title>One night only</title>
		<artist>Bee Gees</artist>
		<country>UK</country>
		<company>Polydor</company>
		<price>10.90</price>
		<year>1998</year>
	</cd>
	<cd>
		<title>Sylvias Mother</title>
 		<artist>Dr.Hook</artist>
		<country>UK</country>
		<company>CBS</company>
		<price>8.10</price>
		<year>1973</year>
	</cd>
	<cd>
		<title>Maggie May</title>
		<artist>Rod Stewart</artist>
		<country>UK</country>
		<company>Pickwick</company>
		<price>8.50</price>
		<year>1990</year>
	</cd>
 	<cd>
 		<title>Romanza</title>
		<artist>Andrea Bocelli</artist>
		<country>EU</country>
		<company>Polydor</company>
		<price>10.80</price>
		<year>1996</year>
	</cd>
	<cd>
		<title>When a man loves a woman</title>
		<artist>Percy Sledge</artist>
		<country>USA</country>
		<company>Atlantic</company>
		<price>8.70</price>
		<year>1987</year>
	</cd>
	<cd>
		<title>Black angel</title>
		<artist>Savage Rose</artist>
		<country>EU</country>
		<company>Mega</company>
		<price>10.90</price>
		<year>1995</year>
	</cd>
	<cd>
		<title>1999 Grammy Nominees</title>
		<artist>Many</artist>
		<country>USA</country>
		<company>Grammy</company>
		<price>10.20</price>
		<year>1999</year>
	</cd>
	<cd>
		<title>For the good times</title>
		<artist>Kenny Rogers</artist>
		<country>UK</country>
		<company>Mucik Master</company>
		<price>8.70</price>
		<year>1995</year>
	</cd>
	<cd>
		<title>Big Willie style</title>
		<artist>Will Smith</artist>
		<country>USA</country>
		<company>Columbia</company>
		<price>9.90</price>
		<year>1997</year>
	</cd>
	<cd>
		<title>Tupelo Honey</title>
		<artist>Van Morrison</artist>
		<country>UK</country>
		<company>Polydor</company>
		<price>8.20</price>
		<year>1971</year>
	</cd>
	<cd>
		<title>Soulsville</title>
		<artist>Jorn Hoel</artist>
		<country>Norway</country>
		<company>WEA</company>
		<price>7.90</price>
		<year>1996</year>
	</cd>
	<cd>
		<title>The very best of</title>
		<artist>Cat Stevens</artist>
		<country>UK</country>
		<company>Island</company>
		<price>8.90</price>
		<year>1990</year>
	</cd>
	<cd>
		<title>Stop</title>
		<artist>Sam Brown</artist>
		<country>UK</country>
		<company>A and M</company>
		<price>8.90</price>
		<year>1988</year>
	</cd>
	<cd>
		<title>Bridge of Spies</title>
		<artist>T`Pau</artist>
		<country>UK</country>
		<company>Siren</company>
		<price>7.90</price>
		<year>1987</year>
	</cd>
	<cd>
		<title>Private Dancer</title>
		<artist>Tina Turner</artist>
		<country>UK</country>
		<company>Capitol</company>
		<price>8.90</price>
		<year>1983</year>
	</cd>
	<cd>
		<title>Midt om natten</title>
		<artist>Kim Larsen</artist>
		<country>EU</country>
		<company>Medley</company>
		<price>7.80</price>
		<year>1983</year>
	</cd>
	<cd>
		<title>Pavarotti Gala Concert</title>
		<artist>Luciano Pavarotti</artist>
		<country>UK</country>
		<company>DECCA</company>
		<price>9.90</price>
		<year>1991</year>
	</cd>
	<cd>
		<title>The dock of the bay</title>
		<artist>Otis Redding</artist>
		<country>USA</country>
		<company>Atlantic</company>
		<price>7.90</price>
		<year>1987</year>
	</cd>
	<cd>
		<title>Picture book</title>
		<artist>Simply Red</artist>
		<country>EU</country>
		<company>Elektra</company>
		<price>7.20</price>
		<year>1985</year>
	</cd>
	<cd>
		<title>Red</title>
		<artist>The Communards</artist>
		<country>UK</country>
		<company>London</company>
		<price>7.80</price>
		<year>1987</year>
	</cd>
	<cd>
		<title>Unchain my heart</title>
		<artist>Joe Cocker</artist>
		<country>USA</country>
		<company>EMI</company>
		<price>8.20</price>
		<year>1987</year>
	</cd>
</catalog>


A continuació tenim el codi font del fitxer XSL (DiscsXML.xsl) que executarem per mostrar les dades del XML anterior:


  <?xml version="1.0" encoding="UTF-8"?>
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:template match="/">
   <pre><html>
   <body>
   <h2>My CD Collection</h2>
     <table border="1">
       <tr bgcolor="#9acd32">
         <th>Title</th>
         <th>Artist</th>
       </tr>
       <xsl:for-each select="catalog/cd">
       <tr>
         <td><xsl:value-of select="title"/></td>
         <td><xsl:value-of select="artist"/></td>
       </tr>
       </xsl:for-each>
     </table>
   </body>
   </html>
  </xsl:template>
  </xsl:stylesheet>




Links a exemples externs

Vegeu També

Manual XPath

Manual XSLT

Sintaxi XSL