Im working with PHP5, and I need to transform XML in the following form:
- some text
-
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.