1

I am in the process of converting some XSLT (more specifically schematron validation rules) from using Altova to Saxon.NET (Saxon-HE version="9.7.0.4") as the XSLT processor. However, I came to a problem which I cannot find a resolution for.

The problem is with the document() function. In my XSLT I have:

<sch:let name="params" value="document('https://some_web_address')"/>

This URL brings back an XML of parameters which the XSLT uses. The problem is that this works in Altova but does not work (returns empty) when I started using Saxon.NET

After trying doc-available()/unparsed-text-available() functions, it seems like none return true for the XML coming from the URL. However, if I create a xml file of the returned xml data, place it in the local directory (local to my XSLT) and specify the full path to the xslt, unparsed-text-available() function returns true, yet doc-available() still returns false. I even created a small dummy XML sample:

<?xml version="1.0" encoding="UTF-8"?>
<parameters>
  <parameter>100</parameter>
</parameters>

The XML is valid, but came back with same exact results (doc-available() = false, unparsed-text-available() = true)

I have looked at some of the other related questions on here (XSLT Document() Function results in Saxon Error/ Attribute-String cant be used as Filepath) but none of them fully resolved my problem.

This issue might have to do something with the base URI of the XSLT sheet, so I run: base-uri(.) and static-base-uri() and both returned empty.

So my questions are:

  • Is is possible to use a URL (web URI) as a parameter to document() with Saxon.NET?
  • If not, what am I doing wrong where doc-available() is false but unparsed-text-available() returns true for a valid xml file (as shown above)?

The ideal solution for me would be to use the URL, but it can be downgraded to using a local file. I would appreciate if anyone can help me with this.

2
  • 1
    Can you post a minimal but complete stylesheet giving the error, together with sample data? I put your dummy XML sample into a file 'test2016112201.xml' into a directory with a stylesheet accessing that file with doc-available($doc1-uri) and doc($doc1-uri)/parameters/parameter and run it with Saxon .NET 9.7 EE and HE and the the result is true<parameter>100</parameter> so that works fine. I simply run transform.exe for that test. It is not clear whether you use the command line tool or some .NET code but you might want to explain and show in more detail how you use Saxon .NET. Commented Nov 22, 2016 at 15:51
  • If unparsed-text-available() is true but doc-available() is false, then it's some kind of problem parsing the XML. It's a strange one; could be due to some kind of configuration settings. Need to know more about how you are running it (e.g. from the command line or from a C# application). Using document() should give you better diagnostics than doc-available(), which will only return true or false and won't tell you why. Commented Nov 22, 2016 at 18:29

1 Answer 1

0

Ok, after a really long research it turned out to be something really stupid on my part.

Issue was that in the code where we are using Saxon.NET we were setting:

xsltExecutable.InputXmlResolver = null

for some unknown reason. It should have been

xsltExecutable.InputXmlResolver = new XmlUrlResolver();

since XmlUrlResolver is what pulls the data from external sources.

I got to this when trying to setup a small schematron test case, which was working fine in the command line, but would not work in .NET app.

This post also helped: How to use the XSLT fn:document function in Saxon-HE to read an XML string?

Thanks guys

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.