Take a look at the following xml. It contains one function level with one room node and a room-container with one room node:
I want to create a report which traverses the level structure and shows information about the rooms underneath them. The traversing is done by creating a repeating section with
/drofus-xml/level as xpath expression. However, the room node underneath the level node is only a reference node (ref node), meaning it links or refers to a corresponding room- container/room node. Ref nodes are used in order to avoid duplicating information several places in the xml file. The link between the two room nodes is that the value of the @ref attribute equals the value of the @id attribute.
When traversing the level node and we find the room ref node, we need a way to retrieve the corresponding room node since it contains all the room data. The way to do this is by creating an index. This is done by manually inserting the following xpath expression into Review->Global XSLT window.
|<xsl:match key="room-index" match="room" use="@id"/>|
It creates an index called "room-index" containing all the room nodes in the xml file that contains a @id attribute. It is possible to create several indexes in the same document. They just need a unique name.
In our report I want to insert a repeating table showing the room name for all the rooms underneath the levels. Then I insert a field with the following xpath expression:
I am in the context of a room ref node which has a @ref attribute. Using the @ref value I retrieve the room node with a matching @id value from the index called "room-index". The xpath expression key('room-index', @ref) returns the room node and it contains a core node with a @name attribute.
Important: The xsl in a building block might require one or more indexes to be defined. This can either be done in the Review->Global XSLT Window for the building block or in the main report using the building block.