XSLT swap
November 25, 2010 11:10 AM   Subscribe

XSLT newbie filter: How would you swap the order of two elements, leaving everything else in a document the same?

I have a simple task I need to perform: take an XML document and swap the order of two elements. The two elements occur in pairs throughout the document, always in the same order. In the output, their order just needs to be reversed. The tags that identify the elements can stay the same. Everything else in the original document--which contains other tags than those two--just needs to flow through the transform and come out the same in the output.
posted by Paquda to Computers & Internet (2 answers total) 2 users marked this as a favorite
Best answer: There's a few ways you could do it. I'd do something like:

1. Use the identity transform template to pass most of the original document through unchanged

2. Have a template match on the first element of the pair, and output the next-sibling first, then output self.

3. Have a template match on the second element of the pair, and don't output anything.

If that doesn't make sense, I can post some code to clarify.
posted by philscience at 12:26 PM on November 25, 2010

Response by poster: Thank you, philscience. That makes sense.
posted by Paquda at 12:32 PM on November 25, 2010

« Older Deliver me MORE!   |   Looking for Oakley c-wire replacement parts. Newer »
This thread is closed to new comments.