differences between for-each and templates in xsl?

前端 未结 7 665
你的背包
你的背包 2020-12-03 10:48

Both xsl:for-each and xsl:template are used to retrieve nodes from xml in an xsl stylesheet. But what is the fundamental difference between them? P

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 11:31

    Both the 'for-each' and 'template' are used to retrieve the nodes from xml in the xsl. But what is the difference between them in basically

    Here are some of the most important differences:

    1. xsl:apply-templates is much richer and deeper than xsl:for-each, even simply because we don't know what code will be applied on the nodes of the selection -- in the general case this code will be different for different nodes of the node-list.

    2. The code that will be applied can be written way after the xsl:apply templates was written and by people that do not know the original author.

    The FXSL library's implementation of higher-order functions (HOF) in XSLT wouldn't be possible if XSLT didn't have the instruction.

    Summary: Templates and the instruction is how XSLT implements and deals with polymorphism.

    Reference: See this whole thread: http://www.stylusstudio.com/xsllist/200411/post60540.html

提交回复
热议问题