XML shredding via XSLT in Java

后端 未结 2 1607
不知归路
不知归路 2020-11-30 13:06

I need to transform large XML files that have a nested (hierarchical) structure of the form


   Flat XML
   Hierarchical XML (multiple blocks, so         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 13:40

    Given the following XML:

    
    
      
    123 A Street
    28 List of previous jobs in the US 3 01/10/2001 38 01/12/2004 6 01/06/2005 10 List of previous jobs in the UK 2 01/05/1999 25 01/07/2001 3 true 6

    The following XSLT:

    
    
    
        
    
        
          
            
          
        
    
      
        
          
            
          
          

    Gives the following output:

    
    
      
        
    123 A Street
    28 List of previous jobs in the US 3 01/10/2001 38 true 6
    123 A Street
    28 List of previous jobs in the US 3 01/12/2004 6 true 6
    123 A Street
    28 List of previous jobs in the US 3 01/06/2005 10 true 6
    123 A Street
    28 List of previous jobs in the UK 2 01/05/1999 25 true 6
    123 A Street
    28 List of previous jobs in the UK 2 01/07/2001 3 true 6

    Note that I've added an Output root element to ensure the document is well formed.

    Is this what you wanted?

    You might also be able to use xsl:copy to copy the higher level elements, but I need to think about this one a bit more. With the above xslt, you have more control, but also you have to redefine your elements...

提交回复
热议问题