Note that there are some explanatory texts on larger screens.

plurals
  1. POXSLT document function with relative URI to allow for http or https
    text
    copied!<p>This is a two part question:</p> <p><strong>1)</strong> I am using the XSLT document function to grab XML from a REST endpoint during a transformation. This works fine if I explicitly add the scheme to the uri, i.e., <code>document('http://...')</code>. However, the final release of the site I'm working on may or may not be accessed securely (https). To compensate for this, is it possible to use a relative URI, i.e., <code>document('//...')</code> in the XSLT document function as you would for other resources like images, etc.?</p> <p>I am attempting to do this with the native .NET <code>XsltCompiledTransform</code> and receiving the following error: <code>"Invalid URI: The hostname could not be parsed."</code> Is this a limitation in .NET and achievable with Saxon or another 2.0 processor or is it just not possible?</p> <p><strong>UPDATE</strong></p> <p>The exception being thrown is an <code>XsltTransformException</code> with an inner <code>UriFormatException</code> with the following stack traces:</p> <pre><code>at System.Xml.Xsl.Runtime.XmlQueryContext.GetDataSource(String uriRelative, String uriBase) at &lt;xsl:template match="Nomination"&gt;(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current) at &lt;xsl:template match="/"&gt;(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current) at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results) at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer) at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver) at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, XmlWriter results) at AAFC.Web.XsltView.Render(ViewContext viewContext, TextWriter writer) </code></pre> <p>Inner stack trace:</p> <pre><code>at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) at System.Uri.CreateUri(Uri baseUri, String relativeUri, Boolean dontEscape) at System.Uri..ctor(Uri baseUri, String relativeUri) at System.Xml.XmlResolver.ResolveUri(Uri baseUri, String relativeUri) at System.Xml.XmlUrlResolver.ResolveUri(Uri baseUri, String relativeUri) at System.Xml.Xsl.Runtime.XmlQueryContext.GetDataSource(String uriRelative, String uriBase) </code></pre> <p><strong>2)</strong> My concern is (and I have not tested this so it may be moot), is that if the final site is accessed securely (https) and the transform is referencing an insecure REST endpoint (http) that problems may arise. Is this a valid concern, or will the transformation happen regardless?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload