Another solution: to use key function.
This solution may work even better because you do not have to define id attribute as having ID type. (actually you can get rid of DTD entirely, wheter it is a good or bad idea). The problem with ID type is that its values must be unique within values of ALL attributes of ID type in a document. Suppose that if you have two attributes of ID type, whose values are received from a database. Each attribute has unique id, but there is no guarantee that they do not use the same (unique for them
) id values. Your resulting document will not be valid.
However, key function will work just fine in this case. I added <anotherCategory> element with the same id values to illustrate the point. Also id attribute on sub element was renamed to IDRef, because it has different semantics.
XML: XSL P.S. Just reading about it right now