XSLT - apply a template to call-template result

后端 未结 1 597
无人共我
无人共我 2021-02-10 10:58

Is it possible to apply a template to the result of a call-template?

For example, the xml and 2 xslt below.

index.xml:



        
1条回答
  •  情深已故
    2021-02-10 12:00

    Is there any way to apply a template to the result of in index.xsl?

    Yes, this is called multi-pass processing. The only peculiarity is that in XSLT 1.0 you must apply the implementation-dependent xxx:node-set() extension function to any intermediate result, which in general will be of the infamous RTF (Result Tree Fragment) type and thus will need to be converted to a regular tree.

    Here is a complete example of multi-pass processing (I am using xsl:apply-templates and not xsl:call-template, but you can freely modify this example to use named templates and xsl:call-template instead):

    
     
    
     
      
       
      
    
      
     
    
     
      
     
    
     
      
     
    
    

    when this transformation is applied on the following XML document:

    
      01
      02
      03
      04
      05
      06
      07
      08
      09
      10
    
    

    the wanted result ( the content of any num elements is doubled in the first pass, then squared in the second pass) is produced:

    4
    16
    36
    64
    100
    144
    196
    256
    324
    400
    

    II. In XSLT 2.0

    The RTF "type" was abolished, so it is much more easier to specify multi-pass processing, which becomes almost indistinguishable from functional composition, as the following equivalent transformation shows:

    
     
    
     
      
     
    
     
      
    
      
       
        
       
      
     
    
     
      
    
      
       
        
       
      
     
    
    

    when this transformation is applied on the same XML document (above), the same correct result is produced:

    4
    16
    36
    64
    100
    144
    196
    256
    324
    400
    

    0 讨论(0)
提交回复
热议问题