Comma separated string parsing XSLT to for-each node

后端 未结 3 1433
無奈伤痛
無奈伤痛 2021-02-07 12:59

I have an input string which has csv values. Eg., 1,2,3 I would need to separate each values and assign to target node in for-each loop.

I got this below template that s

3条回答
  •  耶瑟儿~
    2021-02-07 13:18

    With XSLT 2.0 you can use tokenize(string, separator) function instead of named template.

    And this xsl:

    
    
        
            
                
                    
                        
                    
                
            
        
    
    

    gives following result:

    
    
        15/12/2011
        16/12/2011
        19/12/2011
        20/12/2011
        21/12/2011
    
    

    Update:

    With Xslt 2.0 processor under backward compatibility mode following template gives the same result:

    
        
            
                
                    
                    
                
            
    
            
                
                    
                
            
        
    
    

    For Xslt 1.0 - it is not possible simple (with standard functions) access to nodes via variable - see @Dimitre Novatchev answer XSLT 1.0 - Create node set and pass as a parameter

    For this purpose XSLT 1.0 processors contains extension function: node-set(...)

    For Saxon 6.5 node-set() function is defined in http://icl.com/saxon namespace

    So in the case of XSLT 1.0 processors solution would be:

    
        
        
    
        
            
                
                    
                        
                        
                    
                
                
                    
                        
                    
                
            
        
    
        
            
            
            
                
                    
                        
                    
                    
                        
                    
                
            
            
            
            
            
                
            
            
                
                    
                    
                        
                    
                
            
        
    
    
    

    Thanks @Dimitre Novatchev to correct me and his answer about accessing node sets from variable.

提交回复
热议问题