Recently, @naruto mentioned the phrase 頭が赤い魚を食べた猫, which can be understood in many ways. There is some ambiguity in how each word relates to each other.
Among other possibilities, it could mean
- [(頭が赤い)魚]を食べた猫 (red-headed fish)
- [(頭が赤い)+(魚を食べた)]猫 (red-headed cat)
The same applies here. Consider the following pattern:
As far as logic and grammar is concerned, this can be interpreted as either one of these possibilities:
Note that A, B, C, and D can be nouns or noun phrases. If the latter, it could get even more confusing, so I won't consider this case.
Usually context resolves the ambiguity and makes it obvious. For the example you gave, that would be possibility (3): the difference between certain kinds of vegetables.
To illustrate the point, let me give some examples for each possibility.
《》 markers added by me for clarity)
- garden COLORING BOOK 《小鳥と花と動物》のぬり絵
Note the first sentence.
I had a hard time coming up with examples for case ③, but it's definitely possible.
To summarize, only context and common sense can tell you what の applies to, it depends on what the nouns or noun phrases A, B, C, and D are.
Lastly, if you really wanted to leave no ambiguity, you could resort to a lengthy phrase that says it explicitly, such as せりとレタスとキャベツという3つの(野菜・植物)の違い.