Includere all'interno XSL XSL
Se XML / XSL Trasforma il tuo domian, poi ci sono momenti in cui ci vogliono un pezzo del codice dinamico da utilizzare elemento di libreria (da effettuarsi riutilizzabile). Quello che voglio dire, probabilmente potrebbe essere reso più chiaro con questo scenario di esempio.
Immaginate di creare un sito web (e l'utilizzo di XML, XSL transfroms ofcourse) e la maggior parte delle pagine avrebbe un modulo commenti. Bene! allora o si copia o incolla il codice in ogni modello di pagina (che io non sono dire, ma fare la manutenzione e rielaborare un incubo) o ancora meglio, si crea un file di inclusione che potrebbe essere tirato in dove mai lo vuoi nella tua pagina ( s) ...
Così come possiamo creare un file XSL INCLUDE e includerlo in un altro file XSL? Ecco come ...
Giusto per fare chiarezza ... ecco breve lista di file che si creerebbe ... qui, ci saranno anche informazioni su frutta e verdura in una pagina padre chiamato cibo.
1. food.xml - file di dati XML su cui la trasformazione sarà applicato
2. food.xsl - file principale XSL, che trasformerà la nostra food.xml
3. inc_fruits.xsl - XSL file di inclusione che il rendering dei dati frutta
4. inc_vegtables.xsl - XSL file di inclusione che il rendering dei dati vetetables
Non credo che ho spiegare molto, i codici per gli elementi di cui sopra, sarà auto esplicativo ...
FOOD.XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="food.xsl"?>
<food>
<date>July 2008</date>
<description>All about things we eat everyday</description>
<fruits type="tropical">
<item name="mango" moreinfo="http://www.mango.com">Mango is the king of fruits</item>
<item name="banana" moreinfo="http://www.banana.com">Banana once a day , keeps the doctor away</item>
<item name="orange" moreinfo="http://www.orange.com">Orange is the color and rich in vitamin C</item>
<item name="Papaya" moreinfo="http://www.papaya.com">Papaya - Hot when raw, cold when ripe</item>
</fruits>
<vegetables>
<item name="spinach" moreinfo="http://www.spinach.com">Spinach is full of iron</item>
<item name="asparagus" moreinfo="http://www.asparagus.com">Asparagus contains loads of vitamin D </item>
<item name="fenugreek" moreinfo="http://www.fenugreek.com">Fenugreek is rich in vitamin C</item>
</vegetables>
</food>
FOOD.XSL
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:include href="inc_fruits.xsl" />
<xsl:include href="inc_vegetables.xsl" />
<xsl:template match="/">
<html>
<head>
<title>Title</title>
</head>
<body>
<h3><xsl:value-of select="/food/description" /></h3>
Modification Date : <xsl:value-of select="/food/date" />
<hr/>
<h5> About Fruits</h5>
<xsl:call-template name="about_fruits"/>
<hr/>
<h5> About Vegetables</h5>
<xsl:call-template name="about_vegetables"/><hr/>
</ Body>
</ Html>
</ Xsl: template>
</ Xsl: stylesheet>
INC_FRUITS.XSL
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1" />
<xsl:template name="about_fruits">
<xsl:for-each select="/food/fruits/item/@*">
attribute name : <xsl:value-of select="name()"/>
attribute value : <xsl:value-of select="."/> <br />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
INC_VEGETABLES.XSL
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1" />
<xsl:template name="about_vegetables">
<xsl:for-each select="/food/vegetables/item/@*">
attribute name : <xsl:value-of select="name()"/>
attribute value : <xsl:value-of select="."/> <br/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>










































