I have the 35mm f2.4 and the 40mm XS. They are both very sharp and have a similar max aperture. Here are the differences:
When wide open, the 35mm has less purple fringing, but more bokeh aberrations (where the bokeh in front and behind the focus takes a certain hue).
The 40mm XS is probably sharper and has faster AF. It also appears to be better built (more solid, more dense) than the 35mm, though the 35mm is still much better than some other cheapo lenses I owned, which are not only made of plastic, but also very cheap plastic.
The 40mm XS has a 27mm filter thread, so for filters and lens caps.. you're on your own (though I heard they can be found online, if not in camera stores). Its lens cap is also a bit weird, because you push it in, but that pushes the element in and changes focus. You should probably switch to MF for this, so you don't move the camera's AF gears.
I don't own the 40mm limited, but what I read is that it is slightly better than the XS in every way, except regarding aperture blades, where the XS has rounded ones. But the general optics model is the same. The limited also has some numbers on it and the focus ring isn't 'in the way' (with the XS the focus ring is relatively big and you tend to move it when trying to mount the lens, which isn't great).
Oh, also, as I am typing this, I noticed the forum has suggested similar threads, which deal with the same lens comparisons:
https://www.pentaxforums.com/forums/pentax-slr-lens-discussion/132945-da-40mm...5mm-2-4-a.html https://www.pentaxforums.com/forums/pentax-slr-lens-discussion/120008-dal-35m...m-2-8-ltd.html
Not sure what they came up with, though.
Edit: and I just uploaded some shots taken with the XS on my 500px page, if you are interested the link is in the sig, they are on the first page. Some images there are also taken with the 35mm, but you would have to sift through the pages find them, and that might be too time consuming. Just check the "focal length" in the bottom right square on the photo to see which lens it is.