Title: Using XSLT how do I get resource links from XML, in a bootstrap loading way?
Tags: java;xml;xslt
Question: I want to do something similar to what a browser does when it loads a web page.
I want the client to be able to request a XML page. The client then receives the XML page, saves it, and then reads the file to see if it needs any more files/resources... etc... until all the resources required for that XML page are on the client machine.
The client is running Java. I want to do as much processing of the XML with XSLT as possible. The Java will handle file opening, saving, and http requests.
An example. The Client receives this XML file
<?xml version="1.0" encoding="UTF-8"?&gt;
<?xml-stylesheet type="text/xsl" href="optimus.xsl"?&gt;
<Bus name="happy fun"&gt;
<Picture image="red.gif"/&gt;
</Bus&gt;
So I want the client to then process the file, realise it needs to request from the server the files optimus.xsl and red.gif. Which the java will do.
I can get the Picture/@image attributes out with XSLT. But I cannot read the "xml-stylesheet" with XSLT. Is there something better for this?

Here is the accepted answer: You can process the processing instruction with <xsl:template match="processing-instruction('xml-stylesheet')"&gt; respectively select it with <xsl:variable name="pi" select="//processing-instruction('xml-stylesheet')"/&gt;. You would then need to parse out the contents with string processing or check whether your XSLT processor supports an extension like Saxon 9 does (http://saxonica.com/documentation/html/functions/saxon/get-pseudo-attribute.html) where you can do e.g. <xsl:template match="processing-instruction('xml-stylesheet')"&gt;<xsl:value-of select="saxon:get-pseudo-attribute('href')"/&gt;...</xsl:template&gt;.
Comment for this answer: You should [**accept**](http://meta.stackoverflow.com/q/527.982.9340) this answer to reward our brilliant Martin Honnen for helping and let future readers know that this is a good solution.  Thanks.
Comment for this answer: That's brilliant! I didn't know you could do that:  Thanks very much.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:10/27/14', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<java><xml><xslt>', 'Title': 'Using XSLT how do I get resource links from XML, in a bootstrap loading way?', 'ViewCount': 251, 'id': 26586092, 'user_AboutMe': '', 'user_AccountId': 503769.0, 'user_DisplayName': 'TinyRacoon', 'user_Reputation': 4436.0, 'user_Views': 130.0, 'user_id': 1523779.0}}