Add repeating XML code n times via xslt template

后端 未结 2 817
离开以前
离开以前 2021-01-26 19:12

I want to repeat the following lines in an XML document n times, n being set in the variable $n


    

        
2条回答
  •  遇见更好的自我
    2021-01-26 19:52

    Here's one option. In the example, the element generate will be replaced by the string $n number of times. I'm using DOE (disable-output-escaping) so the string is actual XML in the output. If it's supposed to be a string, just remove the DOE attribute.

    XML Input

    
        
    
    

    XSLT 1.0

    
        
        
    
        
        
            WSCEAllergens[i]
            ]]>
        
    
        
        
            
                
            
            
    
        
            
                
            
        
    
        
            
            
            
            
                
                    
                    
                
            
        
    
    
    

    XML Output

    (Formatted after transform. Actual output would be on a single line because of the normalize-space().)

    
        
            WSCEAllergens[0]
        
        
            WSCEAllergens[1]
        
        
            WSCEAllergens[2]
        
    
    

    Also note that the namespace prefix ss should be bound to a namespace in the output.

提交回复
热议问题