• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 509
  • Last Modified:

override xml-stylesheet in XML file

I have been sent an XML file from a supplier that that contains an xml-stylesheet instruction in it.
<?xml-stylesheet type="text/xsl" href="http://www/myweb/eBIS-XML-Order-v3.xsl" ?>
I need to transform this XML file into a format that my business system can use and I would normally use XSLT to do that.
The problem is that when I try to transform the XML with my XSLT the parser tries to look for the XSL file embedded in the XML and fails.
Is there any way using XSLT that I can stop this behaviour or will I have to resort to parsing the XML with something else to remove the instruction.
  • 4
  • 3
1 Solution
Geert BormansInformation ArchitectCommented:
How do you execute your XSLT?
Most processors simply ignore this process instruction, it is usually just picked up by browsers.
I tried a number of settings on how I usually execute XSLT, using different processors in different architectures,
and the processing instruction is always gracefully ignored
Can you be more specific on how the XSLT process is launched?
The XSLT processor usually requires an indication on which stylesheet is used, so I bet it happens prior to the processor seeing the file, likely simply in the XML parser. If your parser tries to interprete the xml-stylesheet, I suspect it has a setting to ignore that.
For that I need to kow, which parser, and how the parsing happens
Geert BormansInformation ArchitectCommented:
If you really can't seem to switch off the processing instruction interpretation
(thinking about it, you must be doing this in a browser)
there are two options you could finally revert to
1. make sure there is such a stylesheet and make that stylesheet an identity transform
2. strip it off prior to parsing the XML
iegAuthor Commented:
Hi Gertone, thanks for the advice.
We are using XML Spy and Xselerator to try and see what is possible.
From your second posting I think that we probably need to strip it off before we try anything
I was hoping to be able to do this in XSLT rather than reverting to C# code and that is where the Catch 22 occurs. It tries to run its XSL before it runs mine.
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Geert BormansInformation ArchitectCommented:
please note that the XML Spy behaviour is very often non standard.
I have tested with various XSLT processors in  both oxygen (www.oxygenxml.com) and stylus studio (www.stylusstudio.com)
and none of them give a problem... so this seems an issue related to the missbehaviour of XML Spy (not a surprise to me)

Since you try to avoid C# in this exercise, I have a feeling that you want to deal with this in a batch process, rather than in an IDE or browser. If that is the case, just try to use a processor (Saxon or Xalan or msml) that si not the xml spy processor
You will not have the problem I believe

So please, explain exactly how you see the full process, I don't think you need to strip anything
iegAuthor Commented:
We have XML files ftp'd to us from suppliers. On arrival in a directory we have a program (that we have written in C#) that takes the XML and transforms it to the correct format. This is done by loading the XML into a DOM and the XSL into an XSL DOM and doing a standard transformation.
This one supplier has the xml-stylesheet instruction in it and this is causing the problem.

We could change the C# program but I was hoping not to have to do that. If we can find a way of gettimg around this via XSLT (or another way) then that would be great. We will rty using Saxon and see where that takes us.
iegAuthor Commented:
Hi Gertone
We have done some more investigation and you were absolutley correct sowe have decided to change our application.
The problem seemed to be XML Spy and on investigation it transpires that the developer who created our automated import program had used Altova (XML Spy's parser) in his .Net application because at the time he needed a parser that would handle XSLT 2.0
We have downloaded Saxon, linked it into the .Net application and we are running tests now. Initial results are good - thank you.
Geert BormansInformation ArchitectCommented:
yes, what applies for XSLT1 (XML Spy not being standard) applies even more for XSLT2
I always recommend to use Saxon for XSLT2, though I have no experience with the .net variant myself.

glad I could be of some help
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now