Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function parseDocument(): XmlParserResult {
}

function processingInstruction(matchDeclaration: boolean): XmlParserNodeWrapper<XmlParserProcessingInstructionNode>|undefined {
const m = matchDeclaration ? match(/^<\?(xml)\s*/) : match(/^<\?([\w-:.]+)\s*/);
const m = matchDeclaration ? match(/^<\?(xml(-stylesheet)?)\s*/) : match(/^<\?([\w-:.]+)\s*/);
if (!m) return;

// tag
Expand Down
24 changes: 24 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,30 @@ describe('XML Parser', function() {
});
});

it('should correctly parse xml-stylesheet as first processing instruction', function() {
const node = xmlParser('<?xml-stylesheet href="style.xsl" type="text/xsl" ?><foo></foo>');

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(`<?xml version="1.0" encoding="utf-8"?>
<!-- Load the stylesheet -->
Expand Down
Loading