A lesson on InlineXSLT

I have a document with two UUID nodes. The question is: how can I retrieve the second node? Complicating factor. The second UUID node is located within two repeating nodes: DocumentResponse and DocumentReference.

First I tried a scripting functoid with the following inline XSLT:
<xsl:value-of select=”/*[local-name()=’ApplicationResponse’ and namespace-uri()=’urn:oasis:names:specification:ubl:schema:xsd:ApplicationResponse-2′]/*[local-name()=’DocumentResponse’ and namespace-uri()=’urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2′][1]/*[local-name()=’DocumentReference’ and namespace-uri()=’urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2′][1]/*[local-name()=’UUID’ and namespace-uri()=’urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2′]/text()” />

This statement returns an empty BusinessTransactionId, so that’s not good.

The correct expression is displayed below:
<xsl:value-of select=”(//*[local-name()=’UUID’ and namespace-uri()=’urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2′])[2]” />

Note the use of brackets in the above example. [ ] has higher priority than //, so you have to override the higher precedence of [] by using those brackets. In stead of [2], I could also have used [last()].

Finally, a necessary warning: The use of the “//” abbreviation is very expensive as it causes the whole (sub)tree to be traversed. Whenever the structure of the document is known, it is recommended to use more specific constructs (location paths).