XSLT templates and recursion

前端 未结 5 1570
孤街浪徒
孤街浪徒 2020-12-29 06:43

Im new to XSLT and am having some problems trying to format an XML document which has recursive nodes.

My XML Code:

Hopefully my XML shows:

  • All
5条回答
  •  不思量自难忘°
    2020-12-29 07:12

    This is easy. The XSLT processor does all the recursion and the looping for you, all you need to do is to specify templates for nodes you want to handle.

    
      
      
        
  • The always is the recursive/iterative step in XSLT. It takes any nodes that fit its select expression and finds templates for them.

    Your job is it to craft an appropriate select expression, supply a template for every node you want to handle and otherwise get out of the way. ;-) Resist the urge to cram everything into one big template or use just because it feels convenient - it is not. Separate templates create more reusable and maintainable, less deeply nested code, and XSLT processors are optimized for template handling, so this might even be the more efficient approach.

提交回复
热议问题