If you have two XML declarations in a file then your file is not XML, and if it is not XML then it cannot be processed using XSLT.
If you want to process non-XML files then you will need to use some non-XML technology to convert them to XML before you start. (However, it's best to try and persuade the supplier to fix their bug if you can. The whole point about standards is that they save costs for everyone provided you actually follow the rules.) If you do need to repair broken XML files, you can sometimes use a utility such as HTML Tidy or validator.nu, or you may need a custom Perl script or similar.
LATER
Actually, I think I should qualify this answer. If you know that your file contains a sequence of well-formed XML documents, each starting with an XML declaration, then it might be feasible to read it in an XSLT 3.0 stylesheet using the unparsed-text()
function, split it into its constituent documents using xsl:analyze-string
, parse each of those documents using the XPath 3.0 parse-xml()
function, and then process the documents as normal. You would have to make sure you knew the file encoding in advance, and you would have to be confident there are no "nasties" in there, like something masquerading as an XML declaration inside a comment or CDATA section.