Help, please

Can anyone help? Thanks in advance.

I have the xml document like:



12345A
22345B
32345A
42345B
52345B
62345A
72345A



And like to transform it to another xml document. For all under , Start adding the folowing with when the last character of context of the is A; otherwise add the with the context when the last character of the context of the is “B”.



12345A
22345B


32345A
42345B
52345B


62345A
72345B

Hi,
I found this question to be quite a challenge because it requires procedural processing of your data, which does not sit comfortably with xsl’s declarative nature. I have attached an example which worked for me - I hope it gives you some ideas. Basically it steps through all the A items. For each A item it creates a new group and copies the A item. Then it locates the next A item, and explicitly copies all the B items which lie between the two A items. Before starting I had to remove whitespace from the xml because it interfered with the principle of node counting.

I would hope that there is a better way to do this, but I couldn’t find one.

HTH
test.xsl (1.56 KB)

Here?s my solution. Remember, modes are our friends.
group.xsl (1.31 KB)