Wrap group of XML nodes

前端 未结 3 879
梦如初夏
梦如初夏 2021-01-19 07:17

Im working with PHP5, and I need to transform XML in the following form:


    some text
    

        
3条回答
  •  礼貌的吻别
    2021-01-19 08:09

    You didn't address this in the original question, so it may not be required. But if the input has multiple sequences of elements that need to be wrapped, that are separated from each other by other sibling elements, e.g.:

    
        some text
        
            some text
            some text          
            some text
            some text
            some text          
        
    
    

    the earlier answers will, I believe, lump the elements together, changing their order:

    
        some text
        
             
                some text
                some text          
                some text
                some text
             
            some text
        
     
    

    Do you want that, or do you want to wrap them separately, like this?

    
        some text
        
             
                some text
                some text          
             
            some text
             
                some text
                some text
             
        
     
    

    If the latter, it will probably be easiest to use an XSLT 2.0 construction. I don't know whether PHP 5 has XSLT 2.0 available, but if you can use such a thing, see this good article.

提交回复
热议问题