Using xsl:include with AJAX/XSLT - ajax

I am using Javascript to load XML and transform it with XSLT. Everything works until I try to use <xsl:include>. Is it possible to include files this way?
Here is the relevant XSLT code.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
...
<xsl:include href="another_xslt.xsl"/>
</xsl:stylesheet>
And here is the javascript code:
var xmlRequest = new XMLHttpRequest();
xmlRequest.open("GET", "data.xml", false);
xmlRequest.send(null);
var xsltRequest = new XMLHttpRequest();
xsltRequest.open("GET", "https://hostname.com/directory/xslt/transform.xsl", false);
xsltRequest.send(null);
var xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xsltRequest.responseXML);
return xsltProcessor.transformToDocument(xmlRequest.responseXML);
I am using Firefox 3.5 and the script fails on the xsltProcessor.importStylesheet line without any error messages.
Update:
Tamper Data shows a request for another_xslt.xsl but in the parent directory so it is getting a 404.
All the xslt files are in https://hostname.edu/directory/xslt/ but Firefox is requesting http://hostname.edu/directory/another_xslt.xsl instead. Why would it be requesting the file from the parent directory and without the https? The html file is in /directory/admin/edit
Using the full URL fixes the problem, but I need it to work on the server, so I would prefer to use the relative path like it is now.

It is possible to xsl-include with importStylesheet() so that shouldn't be the problem.
I do not really have the answer but perhaps some pointers to verify:
Do you have an infinite inclusion recursion where file x includes y which in turn includes x?
Make sure the xsl:include is not followed by an xsl:import.
If you use something like Tamper Data do you see FireFox requesting 'another_xslt.xsl' ?
Long shot guess: I never seen an xsl:include that wasnt defined straight under xsl:stylesheet before any xsl:template declarations perhaps moving this xsl:include declaration to the top might help (keeping in mind it xsl:import should go first).

Related

Bundleconfig (seemingly) not creating requested .js files

We have a large solution with a number of files being created by bundleconfig.cs. But for some reason the last two projects added to the solution don't seem to be getting the files creating. The pages that use them fail cause they aren't there, or not being found.
Example of project successfully getting the files created:
const string ANGULAR_APP_ROOT_EDI = "~/app/ediViewer/";
const string VIRTUAL_BUNDLE_PATH_EDI = ANGULAR_APP_ROOT_EDI + "main.js";
bundles.Add(
new ScriptBundle(VIRTUAL_BUNDLE_PATH_EDI)
.Include(ANGULAR_APP_ROOT_EDI + "ediViewerApp.js")
.IncludeDirectory(ANGULAR_APP_ROOT_EDI, "*.js", searchSubdirectories: true)
);
Example of one that's not:
const string ANGULAR_APP_ROOT_EDI_SC = "~/app/SupplyChain/";
const string VIRTUAL_BUNDLE_PATH_EDI_SC = ANGULAR_APP_ROOT_EDI_SC + "main.js";
bundles.Add(
new ScriptBundle(VIRTUAL_BUNDLE_PATH_EDI_SC)
.Include(ANGULAR_APP_ROOT_EDI_SC + "SupplyChainApp.js")
.IncludeDirectory(ANGULAR_APP_ROOT_EDI_SC, "*.js", searchSubdirectories: true)
);
very similar, both Angular(js) projects with similar directory structures. but the second one gets no files. I have other projects with a similar structure that are working.
I was hoping there was a way to put breakpoints in the bundleconfig file to see if if it was hitting the code, but apparently you can't, or I didn't successfully set one up.
There are a number of bundles appearing after the new one (the standard Angular libraries) that are getting created, so it doesn't appear to be stopping in the middle or anything.
The workaround was I simply added the scripts needed manually to the aspx page, but I shouldn't have to. It's happened for two new projects so far, so I'm prepared to bet it may happen for a third, so if I can find a fix it'd be useful.
Any ideas what might be happening, or how I can troubleshoot it?

How do I open a bitmap from a URI that is the result of taking a camera picture?

I'm pretty bewildered here and have tried numerous suggestions I've seen on SO. I was following the Xamarin recipe for accessing the camera on Android and taking a picture. There were some things missing/out of date, but regardless I got to the point where I need to call BitmapFactory.DecodeFile so I can open the image the user just took and resize it to display in my view. The problem I ran into is that I can't use file paths, I have to use URIs. So I followed the instructions in this SO thread
and set up my file provider stuff. I have this file in my resources/xml directory: provider_paths.xml (MyApp being renamed from my actual app details)
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="MyApp" path="."/>
</paths>
Then in the manifest I added this inside the section:
<provider android:name="android.support.v4.content.FileProvider" android:authorities="com.myapp.provider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/provider_paths" />
</provider>
I ensure the directory exists by doing:
var file = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "MyApp");
Directory = file.AbsolutePath;
if (!file.Exists())
file.Mkdirs();
(Directory being a string variable).
I create the intent and file name like so:
Intent intent = new Intent(MediaStore.ActionImageCapture);
var file = new File(Directory, $"myPhoto_{Guid.NewGuid()}.jpg");
BaseFilename = file.Name;
_uri = FileProvider.GetUriForFile(MainActivity.Instance, "com.myapp.provider", file);
intent.PutExtra(MediaStore.ExtraOutput, _uri);
intent.AddFlags(ActivityFlags.GrantReadUriPermission);
(BaseFilename being a string variable in this class)
At first I thought maybe I should somehow convert the URI to a file path so that I can call BitmapFactory.DecodeFile. I followed several SO threads and none of them worked. I got various exceptions when they all started doing ContentResolver.Query or cursor operations.
So I figured, well, there's a BitmapFactory.DecodeStream method, why not use that instead? I tried getting a stream from the URI like so:
var stream = MainActivity.Instance.ContentResolver.OpenInputStream(_uri)
But when I do this I get an exception: Java.Lang.Exception: open failed: ENOENT (No such file or directory)
An example of what the URI looks like when I try this:
content://com.myapp.provider/MyApp/Pictures/MyApp/myPhoto_2d13056f-6d23-461a-ad4b-532e10d9cb75.jpg
I'm so confused at this point about what's even the problem, and having a hard time with a lot of outdated Xamarin samples that I don't know where to look or what even is the real underlying problem here. Any insight would be greatly appreciated. BTW in case it matters, I at least go the permission stuff right. I already prompted for camera and storage access (I already dealt with errors regarding not having permission for camera/read/write external storage so at least that's over with).
OMG, I just figured it out after 2 days of banging my head against a wall. It turns out that taking a nap is in fact quite helpful. I thought I had got all my permission requests dealt with. But then I started exploring my device's file structure and noticed that the images weren't being saved. Which is really odd because last night the images were in fact saving. I can see them and the date stamp. Anyway I decided to try to prompt for WRITE_EXTERNAL_STORAGE permission (already did this with READ and CAMERA) and all problems solved.

Windows Phone webclient caching "issue"?

I am trying to call the same link, but with different values, the issue is that the url is correct containing the new values but when I download it (Webclient.DownloadStringTaskAsync), it gives me the previous calls result.
I have tried adding headers no-cache, and attaching a random value to the call, and ifmodifiedSince header. however it is still not working.
any help will be much appreciated cause I have tried everything.
uri: + "&junk=" + Guid.NewGuid());
client.Headers["Cache-Control"] = "no-cache";
client.Headers[HttpRequestHeader.IfModifiedSince] = DateTime.UtcNow.ToString();
var accessdes = await client.DownloadStringTaskAsync(uri3);
so here my uri3 contains the latest values, but when I hover over accessdes, it contains the result as if I am making a old uri3 call with previous set data.
I saw one friend that was attaching a random GUID to the Url in order to prevent the OS to cache its content. For example:
if the Url were: http://www.ms.com/getdatetime and the OS is caching it.
Our solution was adding a guid for creating "sort of" like a new url, as an example our previous Url would look like: http://www.ms.com/getdatetime?cachebuster=21EC2020-3AEA-4069-A2DD-08002B30309D
(see more about cache buster : http://www.adopsinsider.com/ad-ops-basics/what-is-a-cache-buster-and-how-does-it-work/ )

ClientGlobalContext.js.aspx broken in Dynamics 2011?

I am trying to implement a custom web resource using jquery/ajax and odata. I ran into trouble and eventually found that when I call:
var serverUrl = context.getServerUrl();
The code throws exceptions.
However, when I change serverUrl to the literal url, it works. I then found forum posts that said I should verify my .aspx page manually by going to https://[org url]//WebResources/ClientGlobalContext.js.aspx to verify that it is working. When I did that I received a warning page:
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
Invalid at the top level of the document. Error processing resource 'https://[org url]//WebResources/Clien...
document.write('<script type="text/javascript" src="'+'\x26\x2347\x3b_common\x26\x2347\x3bglobal.ashx\x26\x2363\x3bver\x2...
What the heck does that mean?
Hard to tell outside of context (pun not intended) of your code, but why aren't you doing this?
var serverUrl = Xrm.Page.context.getServerUrl();
(Presumably, because you have defined your own context var?)
Also, this method is deprecated as of Rollup 12, see here: http://msdn.microsoft.com/en-us/library/d7d0b052-abca-4f81-9b86-0b9dc5e62a66. You can now use getClientUrl instead.
I now it is late but hope this will be useful for other people who will face this problem.
Until nowadays even with R15 there are two available ClientGlobalContext.js.aspx
https://[org url]/WebResources/ClientGlobalContext.js.aspx (the bad one)
https://[org url]/[organization name]/[publication id]/WebResources/ClientGlobalContext.js.aspx (The good one)
I don't know why exist 1. but it causes many issues like:
It could not be published or hold information (Your case #Steve).
In a deployment with multiple organizations, seems it saves info only for the last organization deployed causing that methods under Xrm.Page.context. will return info from a fixed organization. Actually each method that underground uses these constants included in ClientGlobalContext.js.aspx: USER_GUID, ORG_LANGUAGE_CODE, ORG_UNIQUE_NAME, SERVER_URL, USER_LANGUAGE_CODE, USER_ROLES, CRM2007_WEBSERVICE_NS, CRM2007_CORETYPES_NS, AUTHENTICATION_TYPE, CURRENT_THEME_TYPE, CURRENT_WEB_THEME, IS_OUTLOOK_CLIENT, IS_OUTLOOK_LAPTOP_CLIENT, IS_OUTLOOK_14_CLIENT, IS_ONLINE, LOCID_UNRECOGNIZE_DOTC, EDIT_PRELOAD, WEB_SERVER_HOST, WEB_SERVER_PORT, IS_PATHBASEDURLS, LOCID_UNRECOGNIZE_DOTC, EDIT_PRELOAD, WEB_RESOURCE_ORG_VERSION_NUMBER, YAMMER_IS_INSTALLED, YAMMER_IS_CONFIGURED_FOR_ORG, YAMMER_APP_ID, YAMMER_NETWORK_NAME, YAMMER_GROUP_ID, YAMMER_TOKEN_EXPIRED, YAMMER_IS_CONFIGURED_FOR_USER, YAMMER_HAS_CONFIGURE_PRIVILEGE, YAMMER_POST_METHOD. For instance method Xrm.Page.context.getUserId() is implemented as return window.USER_GUID;
To be sure that your URL is the correct just follow the link posted by #Chris

ChemDoodle Ajax Incompatibility with Pollen.js

I'm trying to use iChemLabs cloud services from a html5 web worker. Normally the cloudservices requires jQuery but I can't import that into a web worker so I'm using Pollen instead with a ChemDoodle Web Components library with which I have stripped out the document-related things.
jQuery.Hive.Pollen provides a nice ajax function very similar to jQuery, but I can't seem to get it to work at all. I know this problem will be tricky to solve considering that Access-control-headers need to be set to allow any of you to actually find the solution. However, I'm a beginning javascript programmer and I was wondering if my two weeks of frustration is actually a small difference. I am trying to invoke the following function:
var cloudmolecule;
ChemDoodle.iChemLabs.readSMILES('N1(C)C(=O)N(C)C(C(=C1N1)N(C=1)C)=O', function(mol){
cloudmolecule = mol;
});
Here is a link to the library code I am using, see the 'q.ajax' call and substitute jQuery = q for p = q (p is for pollen) in that block of code.
Right now I'm just trying to get the ajax call to work in an ordinary block of javascript with the plan to migrate to a web worker later.
If anybody could point out the problem to me I would be extremely grateful.
solved! turns out iChemLabs rejects these two extra headers that pollen creates:
_xhr.setRequestHeader("X-Requested-With", "Worker-XMLHttpRequest");
_xhr.setRequestHeader("X-Worker-Hive", "Pollen-JS" );
Simply comment them out
Also, Pollen ajax seems to return a JSON object containing the data in JSON format AND as a string, so do
o = JSON.parse(data.string)//data is the parameter to the callback function
The reduced ChemDoodle library (without document-related methods) will work like a charm with pollen ajax.

Resources