How are template templates applied?

I just started to learn XSL (T) and I wonder how apply-templatesto work? I do not understand that recursively applies templates to it, as written in my book.

            

I understand the XPath part of XSL (T) and so on, but not what it does apply-templates, and why I write it several times.

+5
source share
3 answers

If you read about the use of templates in a book, but did not understand this, then it is not clear that here are a few words. Perhaps you need another book: different styles of styles appeal to different people. Or maybe an interactive tutorial like http://vimeo.com/15234803 will get ideas.

, . xsl: apply-templates , ( ) , . ; - / , .

+3

<xsl:apply-templates> <xsl:template>: s, .

<xsl:apply-templates> node .

, select apply-templates.

. w3schools:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2>My CD Collection</h2>
  <xsl:apply-templates/>
  </body>
  </html>
</xsl:template>

<xsl:template match="cd">
  <p>
  <xsl:apply-templates select="title"/>
  <xsl:apply-templates select="artist"/>
  </p>
</xsl:template>

<xsl:template match="title">
  Title: <span style="color:#ff0000">
  <xsl:value-of select="."/></span>
  <br />
</xsl:template>

<xsl:template match="artist">
  Artist: <span style="color:#00ff00">
  <xsl:value-of select="."/></span>
  <br />
</xsl:template>

</xsl:stylesheet>
  • apply-templates cd , "cd".

  • cd, , title artist <cd>.

  • title artist. , artist title XML .

apply-templates .

+8

If you understand the rules of the template, you are done! Even if it is not so simple, they always amaze. Read the specifications .

+1
source

All Articles