Limitations of IDs

To this point, we’ve been able to generate cross-references easily. There are some limitations of the ID datatype and the id() function, though:

  • If you want to use the ID datatype, you have to declare the attributes that use that datatype in your DTD or schema. Unfortunately, if your DTD is defined externally to your XML document, the XML parser isn’t required to read it. If the DTD isn’t read, then the parser has no idea that a given attribute is of type ID. Similarly, if you’re using a schema, you have to make sure your XSLT processor validates your XML document against the schema to ensure that the ID, IDREF, and IDREFS datatypes are used correctly.

  • You must define the ID, IDREF, and IDREFS relationship in the XML document. It would be nice to have the XML document define the data only, with the relationships between parts of the document defined externally (say, in a stylesheet). That way, if you need to define a new relationship between parts of the document, you could do it by creating a new stylesheet, and you wouldn’t have to modify your XML document. It becomes unwieldy quickly if you have to change the XML document structure every time you need to define a new relationship between parts of the document.

  • An element can have at most one attribute of type ID. If you’d like to refer to the same element in more than one way, you can’t use the id() function.

  • Any given ID value can be found on one element at most. If you’d like to refer to more than one element ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.