Merge functionality of two xsl files into a single file (continued…)

后端 未结 3 766
鱼传尺愫
鱼传尺愫 2021-01-24 11:49

This is in continuation of my question:

Merge functionality of two xsl files into a single file (not a xsl import or include issue)


I have to merge

3条回答
  •  情歌与酒
    2021-01-24 12:18

    I. Performing a chain of transformations is used quite often in XSLT applications, though doing this entirely in XSLT 1.0 requires the use of the vendor-specific xxx:node-set() function. In XSLT 2.0 no such extension is needed as the infamous RTF datatype is eliminated there.

    Here is an example (too-simple to be meaningful, but illustrating completely how this is done):

    
     
    
     
       
        
       
    
       
    
       
     
    
     
      
     
    
     
      
        
      
     
    
    

    when this transformation is applied on the following XML document:

    
      01
      02
      03
      04
      05
      06
      07
      08
      09
      10
    
    

    the wanted, correct result is produced:

    2
    6
    10
    14
    18
    

    Explanation:

    1. In the first step the XML document is transformed and the result is defined as the value of the variable $vrtfPass1. This copies only the num elements that have odd value (not even).

    2. The $vrtfPass1 variable, being of type RTF, is not directly usable for XPath expressions so we convert it to a normal tree, using the EXSLT (implemented by most XSLT 1.0 processors) function ext:node-set and defining another variable -- $vPass1 whose value is this tree.

    3. We now perform the second transformation in our chain of transformations -- on the result of the first transformation, that is kept as the value of the variable $vPass1. Not to mess with the first-pass template, we specify that the new processing should be in a named mode, called "pass2". In this mode the value of any num element is multiplied by two.

    See also the answer of Michael Kay to your first question, which also explained this general technique.

    II. XSLT 2.0 solution (no RTFs):

    
     
    
     
      
       
      
       
     
    
     
      
     
    
     
      
        
      
     
    
    

    III. Using the compose() and compose-flist() functions/templates of FXSL

    The FXSL library provides two convenient functions/template that support easy chaining of transformations. The former composes two functions/transformations while the latter composes all functions/transformations that are provided in a sequence.

    Here is a simple, complete code example:

    
      
      
    
      
    
      
      
      
    
    
      
    
        
        
        Compose:
        (*3).(*2) 3 = 
        
          
          
          
        
    
        
          
          
          
        
    
        Multi Compose:
        (*3).(*2).(*3) 2 = 
        
          
          
        
      
    
      
        
    
        
      
    
      
        
    
        
      
    
    

    When this transformation is applied on any XML document (not used), the wanted, correct results are produced:

    Compose:
    (*3).(*2) 3 = 
    18
    
    Multi Compose:
    (*3).(*2).(*3) 2 = 
    36
    

提交回复
热议问题