override xml-stylesheet in XML file

Posted on 2009-12-21
Last Modified: 2013-11-18
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.
Question by:ieg
    LVL 60

    Expert Comment

    by:Geert Bormans
    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
    LVL 60

    Expert Comment

    by:Geert Bormans
    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

    Author Comment

    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.
    LVL 60

    Accepted Solution

    please note that the XML Spy behaviour is very often non standard.
    I have tested with various XSLT processors in  both oxygen ( and stylus studio (
    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

    Author Comment

    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.

    Author Comment

    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.
    LVL 60

    Expert Comment

    by:Geert Bormans
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Suggested Solutions

    Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
    It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now