2007.04.11 18:56 xsl:for-each vs xsl:apply-templates

Nieraz mnie pytacie, drogie wielbicielki, po co w XSLT stosować <xsl:apply-templates>, skoro zawsze można je zastąpić prostszym <xsl:for-each>. Na specjalną prośbę Danki z Lęborka Kujawskiego zamieszczam więc przykład, który trudno byłoby zrobić for-eachem:

bohaterowie.xml:

<?xml version="1.0" encoding="WINDOWS-1250"?>
<?xml-stylesheet type="text/xsl" href="bohaterowie.xsl"?>
<bohaterowie>
	<bohater_negatywny>Teofil Rozyc</bohater_negatywny>
	<bohater_pozytywny>Janek Bohatyrowicz</bohater_pozytywny>
	<bohater_negatywny>Teresa Plinska</bohater_negatywny>
	<bohater_pozytywny>Benedykt Korczynski</bohater_pozytywny>
	<bohater_pozytywny>Witold Korczynski</bohater_pozytywny>
	<bohater_negatywny>Boleslaw Kirlo</bohater_negatywny>
</bohaterowie>

bohaterowie.xsl:

<?xml version="1.0" encoding="WINDOWS-1250"?>

<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="bohaterowie">
<html>
<body>
<h1>bohaterowie Nad Niemnem</h1>
<div>
<xsl:apply-templates />
</div>
</body>
</html>
</xsl:template>

<xsl:template match="bohater_negatywny">
<p><font color="red"><xsl:value-of select="."/></font></p>
</xsl:template>

<xsl:template match="bohater_pozytywny">
<p><font color="green"><xsl:value-of select="."/></font></p>
</xsl:template>

</xsl:transform>



komentarze:

ksywa:

tu wpisz cyfrę cztery: (to takie zabezpieczenie antyspamowe)

komentarze wulgarne albo co mi się nie spodobają będę kasował


powrot na strone glowna

RSS