diff --git a/src/index.ts b/src/index.ts index b9dae14..0c64879 100644 --- a/src/index.ts +++ b/src/index.ts @@ -129,7 +129,7 @@ function parseDocument(): XmlParserResult { } function processingInstruction(matchDeclaration: boolean): XmlParserNodeWrapper|undefined { - const m = matchDeclaration ? match(/^<\?(xml)\s*/) : match(/^<\?([\w-:.]+)\s*/); + const m = matchDeclaration ? match(/^<\?(xml(-stylesheet)?)\s*/) : match(/^<\?([\w-:.]+)\s*/); if (!m) return; // tag diff --git a/test/index.ts b/test/index.ts index b4e240d..ca8dbbc 100644 --- a/test/index.ts +++ b/test/index.ts @@ -580,6 +580,30 @@ describe('XML Parser', function() { }); }); + it('should correctly parse xml-stylesheet as first processing instruction', function() { + const node = xmlParser(''); + + const root: XmlParserElementNode = { + type: 'Element', + name: 'foo', + attributes: {}, + children: [] + }; + + assert.deepEqual(node, { + declaration: { + name: 'xml-stylesheet', + type: 'ProcessingInstruction', + attributes: { + href: 'style.xsl', + type: 'text/xsl' + } + }, + root: root, + children: [root] + }); + }); + it('should support complex XML', function() { const node = xmlParser(`