What's so bad about xsl:for-each?

后端 未结 5 1979
春和景丽
春和景丽 2021-01-12 23:35

I hear time and time again about how you should avoid the use of XSLT for-each. That it\'s your inner imperative programming demon that should be banished.

What\'s

5条回答
  •  悲哀的现实
    2021-01-12 23:58

    By using apply-templates, perhaps with a mode, makes it easier to include appropriate transformations of more kinds of elements that may be of interest at that location.

    For example if you had XML containing a libraries contents, and you keep using for-each all over the place to select books, then you start keeping record of DVDs, CDs, Ginger Nut biscuits, etc, you will have to examine all the for-each sections to include more than just books. If you had used apply-templates, you may be able to simply create the new matches for the new elements.

提交回复
热议问题