how to filter nodes in xml using xslt..?

后端 未结 3 990
情歌与酒
情歌与酒 2021-01-14 00:13

suppose i have this xml:


    
        amit
        /abc/kk/final.c
        &         


        
3条回答
  •  再見小時候
    2021-01-14 01:03

    This transformation:

    
     
     
    
    
     
      
     
    
     
         
     
    
         
    
    

    when applied to the provided XML document:

    
        
            amit
            /abc/kk/final.c
            22
        
        
            sumit
            /abc/kk/up.h
            23
        
        
            nikhil
            /xyz/up.cpp
            24
        
        
            bharat
            /abc/kk/down.h
            25
        
        
            ajay
            /simple/st.h
            27
        
    
    

    produces the wanted, correct result:

    
       amit
       /abc/kk/final.c
       22
    
    
       sumit
       /abc/kk/up.h
       23
    
    
       bharat
       /abc/kk/down.h
       25
    
    

    Explanation:

    1. A template matching any student having a file child whose string value starts with '/abc/kk'. This just puts the generated contents in a wrapper tr element.

    2. A template matching any student that has no body and effectively deletes it (doesn't copy this element to the output). This template has a lower priority than the first one, because the first one is more specific. Therefore, only student elements that are not matched by the first template are processed with the second template.

    3. A template matching any child element of any student element. This just wraps the content into a td element.

提交回复
热议问题