Question for the practitioners here.
If you wanted to retrieve and then mash-up 3 distinct XML documents within an API Proxy, how would you do it?
I can think of multiple ways.
- write a Java callout to do the work, relying on org.w3c.dom.Document etc
- rely on XSLT and the document() function to retrieve stuff from within XSLT, then use xsl:copy-of
- use nodejs and whatever XML parser is available there to prune-graft elements together.
There are probably others. Which approach would you use and why?
Solved! Go to Solution.
Here's one way to do it: using the document() function in xslt. This function loads a document from a URL. So, set the URLs in a prior policy, then pass those locations into the XSLT as parameters, then mash them up like so:
(In this example, the documents in question are FHIR documents. )
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fhir="http://hl7.org/fhir"> <xsl:output indent="yes"/> <xsl:strip-space elements="*"/> <!-- these are parameters set in the XSL Policy config --> <xsl:param name="loc1" select="''"/> <xsl:param name="loc2" select="''"/> <xsl:param name="loc3" select="''"/> <!-- the following retrieves the remote documents into variables available to the stylesheet --> <xsl:variable name="xdoc1" select="document($loc1)"/> <xsl:variable name="xdoc2" select="document($loc2)"/> <xsl:variable name="xdoc3" select="document($loc3)"/> <xsl:template match="/"> <!-- Mashup 3 FHIR documents --> <!-- for now, we omit the link (self, next) elements --> <Bundle xmlns="http://hl7.org/fhir"> <xsl:copy-of select="$xdoc1/fhir:Bundle/fhir:entry"/> <xsl:copy-of select="$xdoc2/fhir:Bundle/fhir:entry"/> <xsl:copy-of select="$xdoc3/fhir:Bundle/fhir:entry"/> </Bundle> </xsl:template> </xsl:stylesheet>
The XSL Policy might look like this:
<XSL name='XSL-Mashup'> <DisplayName>XSL-Mashup</DisplayName> <Source>dummyRequest</Source> <OutputVariable>response.content</OutputVariable> <ResourceURL>xsl://mashup.xsl</ResourceURL> <Parameters ignoreUnresolvedVariables='true'> <Parameter name='loc1' ref='loc1'/> <Parameter name='loc2' ref='loc2'/> <Parameter name='loc3' ref='loc3'/> </Parameters> </XSL>
There is a dummyRequest (Message object) because I don't want the XSL to use what's in the request. I want to only grab some external content. Each of loc1, loc2, loc3 carry a string which is a url that will return an XML document.
This works only when there is no security on the FHIR / XML endpoints.