[Home] [By Thread] [By Date] [Recent Entries]
On 08.06.2018 20:19, Costello, Roger L. costello@xxxxxxxxx wrote:
I have instance documents containing a bunch of <airport> elements. I want to extract one of the <airport> elements. But the <airport> element might contain IDREF elements, so the result document must include the <airport> element and the referenced elements. Those referenced elements might contain IDREF elements, so the result document must include those referenced elements as well. And on and on and on. Further, while collecting those referenced elements, there might be a reference to an element that has already been collected; I don't want to collect elements twice. I would like to extract the <airport> element with ICAO = KBOS (Boston airport). The following result document contains the desired <airport> element plus all the recursively referenced elements: I've written an XSLT program to do the job. See below. I am wondering if there is a better (simpler, clearer) solution? You could use a key <xsl:key name="ref" match="Airports/*" use="id"/> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" then instead of airport[ICAO eq 'KBOS'] you can use key('ref', 'KBOS') </Results> and here you could use <xsl:variable name="referenced-elements" select="key('ref', $elements-to-process//ref, $doc)"/> <xsl:variable name="new-elements-to-process" select="$referenced-elements except $processed-elements" />
|

Cart



