2

I'm processing remote XML (by just providing URL to XSLT processor) and I can't make it "fetch" additional XML resources. I read similar questions here, but none of them seem like applicable here.

Here is excerpt of remote XML that is being processed:

...
<item>
    <position>1</position>
    <rec id="05a59ca2"/>
</item>
<item>
    <position>2</position>
    <rec id="48e7c3f1"/>
</item>
...

Now these id attributes can be used to refer remote XML source (http://some-server/id) where additional details about each record is stored, and I would like to be able to process them with same XSLT without using other tools, for convenience and simplicity.

So, can I process remote XML files with XSLT?

theta
  • 24,593
  • 37
  • 119
  • 159

1 Answers1

1

You can most certainly do this using the document function

example:

<xsl:variable name="url" select="concat('http://mysite.com/',$id)" />
<xsl:variable name="IDmeta" select="document($url)"/>

to test you can do

<xsl:copy-of select="$IDmeta"/>

to see what the format is

reference

http://www.w3schools.com/xsl/func_document.asp

Treemonkey
  • 2,133
  • 11
  • 24
  • Isn't `document()` only available for local files? Just in case I tried it as in your example and got `Error retrieving resource` for provided URL. – theta Jul 24 '12 at 15:15
  • You know what? It works beautifully! Not for first example, but for another with absolute path to XML file. For some reason, I didn't considered `document()` as from what I have read over Internet I was under impression that it's not that easy ;) edit: you were faster – theta Jul 24 '12 at 15:23
  • superb, just been doing some things with it myself to dynamically load a pre defined list of things also note you can use xpath on this aswell example like document('your-path.xml')/Categories/Category[@ID = $CategoryID] – Treemonkey Jul 24 '12 at 15:25
  • Yes, I was hoping for that :) – theta Jul 24 '12 at 15:31