@tradik/xslt-processor 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -2
- package/dist/xslt-processor.browser.js +2 -2
- package/dist/xslt-processor.browser.js.map +2 -2
- package/dist/xslt-processor.browser.min.js +1 -1
- package/dist/xslt-processor.browser.min.js.map +2 -2
- package/dist/xslt-processor.cjs +2 -2
- package/dist/xslt-processor.cjs.map +2 -2
- package/dist/xslt-processor.js +2 -2
- package/dist/xslt-processor.js.map +2 -2
- package/package.json +1 -1
- package/src/xslt/engine.js +4 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var XsltProcessorLib=(()=>{var v=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var V=(m,e)=>{for(var t in e)v(m,t,{get:e[t],enumerable:!0})},$=(m,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of M(e))!B.call(m,r)&&r!==t&&v(m,r,{get:()=>e[r],enumerable:!(s=F(e,r))||s.enumerable});return m};var H=m=>$(v({},"__esModule",{value:!0}),m);var j={};V(j,{VERSION:()=>K,XPathContext:()=>E,XPathEvaluator:()=>g,XPathResultType:()=>R,XSLTProcessor:()=>y,XsltContext:()=>S,XsltEngine:()=>A,default:()=>I,evaluateXPath:()=>O,installGlobal:()=>k,isBrowser:()=>Q,isNativeXSLTSupported:()=>_,isNode:()=>W,parseXPath:()=>T,selectFirstXPath:()=>U,selectXPath:()=>D});var o={NUMBER:"NUMBER",LITERAL:"LITERAL",SLASH:"SLASH",DOUBLE_SLASH:"DOUBLE_SLASH",PIPE:"PIPE",PLUS:"PLUS",MINUS:"MINUS",STAR:"STAR",DIV:"DIV",MOD:"MOD",EQUALS:"EQUALS",NOT_EQUALS:"NOT_EQUALS",LT:"LT",LTE:"LTE",GT:"GT",GTE:"GTE",AND:"AND",OR:"OR",LPAREN:"LPAREN",RPAREN:"RPAREN",LBRACKET:"LBRACKET",RBRACKET:"RBRACKET",AXIS:"AXIS",AT:"AT",DOT:"DOT",DOUBLE_DOT:"DOUBLE_DOT",DOUBLE_COLON:"DOUBLE_COLON",NAME:"NAME",NCNAME:"NCNAME",PREFIX:"PREFIX",FUNCTION:"FUNCTION",NODE_TYPE:"NODE_TYPE",COMMA:"COMMA",DOLLAR:"DOLLAR",COLON:"COLON",EOF:"EOF"},Y=new Set(["ancestor","ancestor-or-self","attribute","child","descendant","descendant-or-self","following","following-sibling","namespace","parent","preceding","preceding-sibling","self"]),z=new Set(["comment","text","processing-instruction","node"]),G=new Set(["and","or","mod","div"]),f=class{constructor(e,t,s){this.type=e,this.value=t,this.position=s}toString(){return`Token(${this.type}, ${JSON.stringify(this.value)}, pos=${this.position})`}},q=new Set([o.AT,o.DOUBLE_COLON,o.LPAREN,o.LBRACKET,o.COMMA,o.SLASH,o.DOUBLE_SLASH,o.PIPE,o.PLUS,o.MINUS,o.STAR,o.DIV,o.MOD,o.EQUALS,o.NOT_EQUALS,o.LT,o.LTE,o.GT,o.GTE,o.AND,o.OR]),b=class{constructor(e){this.expression=e,this.position=0,this.tokens=[]}getLastToken(){return this.tokens.length>0?this.tokens[this.tokens.length-1]:null}isOperatorContext(){let e=this.getLastToken();return!(!e||q.has(e.type))}tokenize(){for(this.tokens=[],this.position=0;this.position<this.expression.length&&(this.skipWhitespace(),!(this.position>=this.expression.length));){let e=this.nextToken();e&&this.tokens.push(e)}return this.tokens.push(new f(o.EOF,null,this.position)),this.tokens}skipWhitespace(){for(;this.position<this.expression.length&&/\s/.test(this.expression[this.position]);)this.position++}peek(e=0){return this.expression[this.position+e]}consume(){return this.expression[this.position++]}nextToken(){let e=this.position,t=this.peek();if(t==='"'||t==="'")return this.readStringLiteral();if(/[0-9]/.test(t)||t==="."&&/[0-9]/.test(this.peek(1)))return this.readNumber();if(t==="/"&&this.peek(1)==="/")return this.position+=2,new f(o.DOUBLE_SLASH,"//",e);if(t==="."&&this.peek(1)===".")return this.position+=2,new f(o.DOUBLE_DOT,"..",e);if(t===":"&&this.peek(1)===":")return this.position+=2,new f(o.DOUBLE_COLON,"::",e);if(t==="!"&&this.peek(1)==="=")return this.position+=2,new f(o.NOT_EQUALS,"!=",e);if(t==="<"&&this.peek(1)==="=")return this.position+=2,new f(o.LTE,"<=",e);if(t===">"&&this.peek(1)==="=")return this.position+=2,new f(o.GTE,">=",e);let s={"/":o.SLASH,"|":o.PIPE,"+":o.PLUS,"-":o.MINUS,"*":o.STAR,"=":o.EQUALS,"<":o.LT,">":o.GT,"(":o.LPAREN,")":o.RPAREN,"[":o.LBRACKET,"]":o.RBRACKET,"@":o.AT,".":o.DOT,",":o.COMMA,$:o.DOLLAR,":":o.COLON};if(s[t])return this.position++,new f(s[t],t,e);if(this.isNameStartChar(t))return this.readName();throw new Error(`Unexpected character '${t}' at position ${this.position} in expression: ${this.expression}`)}readStringLiteral(){let e=this.position,t=this.consume(),s="";for(;this.position<this.expression.length&&this.peek()!==t;)s+=this.consume();if(this.position>=this.expression.length)throw new Error(`Unterminated string literal at position ${e}`);return this.consume(),new f(o.LITERAL,s,e)}readNumber(){let e=this.position,t="";for(;this.position<this.expression.length&&/[0-9]/.test(this.peek());)t+=this.consume();if(this.peek()==="."&&/[0-9]/.test(this.peek(1)))for(t+=this.consume();this.position<this.expression.length&&/[0-9]/.test(this.peek());)t+=this.consume();return new f(o.NUMBER,parseFloat(t),e)}readName(){let e=this.position,t="";for(;this.position<this.expression.length&&this.isNameChar(this.peek());)t+=this.consume();if(this.skipWhitespace(),Y.has(t)&&this.peek()===":"&&this.peek(1)===":")return new f(o.AXIS,t,e);let s=this.position;if(this.skipWhitespace(),this.peek()==="(")return z.has(t)?new f(o.NODE_TYPE,t,e):new f(o.FUNCTION,t,e);if(this.position=s,G.has(t)&&this.isOperatorContext()){let r={and:o.AND,or:o.OR,mod:o.MOD,div:o.DIV};return new f(r[t],t,e)}return new f(o.NAME,t,e)}isNameStartChar(e){if(!e)return!1;let t=e.charCodeAt(0);return e==="_"||t>=65&&t<=90||t>=97&&t<=122||t>=192}isNameChar(e){if(!e)return!1;let t=e.charCodeAt(0);return this.isNameStartChar(e)||e==="-"||e==="."||t>=48&&t<=57}};function x(m){return new b(m).tokenize()}var c={OR_EXPR:"OrExpr",AND_EXPR:"AndExpr",EQUALITY_EXPR:"EqualityExpr",RELATIONAL_EXPR:"RelationalExpr",ADDITIVE_EXPR:"AdditiveExpr",MULTIPLICATIVE_EXPR:"MultiplicativeExpr",UNARY_EXPR:"UnaryExpr",UNION_EXPR:"UnionExpr",PATH_EXPR:"PathExpr",LOCATION_PATH:"LocationPath",STEP:"Step",PREDICATE:"Predicate",VARIABLE_REF:"VariableRef",LITERAL:"Literal",NUMBER:"Number",FUNCTION_CALL:"FunctionCall",NAME_TEST:"NameTest",NODE_TYPE_TEST:"NodeTypeTest",PI_TEST:"ProcessingInstructionTest"},u=class{constructor(e,t={}){this.type=e,Object.assign(this,t)}},w=class{constructor(e){this.tokens=e,this.position=0}parse(){let e=this.parseExpr();if(!this.isAtEnd())throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().position}`);return e}parseExpr(){return this.parseOrExpr()}parseOrExpr(){let e=this.parseAndExpr();for(;this.match(o.OR);){let t=this.parseAndExpr();e=new u(c.OR_EXPR,{left:e,right:t})}return e}parseAndExpr(){let e=this.parseEqualityExpr();for(;this.match(o.AND);){let t=this.parseEqualityExpr();e=new u(c.AND_EXPR,{left:e,right:t})}return e}parseEqualityExpr(){let e=this.parseRelationalExpr();for(;;)if(this.match(o.EQUALS)){let t=this.parseRelationalExpr();e=new u(c.EQUALITY_EXPR,{operator:"=",left:e,right:t})}else if(this.match(o.NOT_EQUALS)){let t=this.parseRelationalExpr();e=new u(c.EQUALITY_EXPR,{operator:"!=",left:e,right:t})}else break;return e}parseRelationalExpr(){let e=this.parseAdditiveExpr();for(;;)if(this.match(o.LT)){let t=this.parseAdditiveExpr();e=new u(c.RELATIONAL_EXPR,{operator:"<",left:e,right:t})}else if(this.match(o.LTE)){let t=this.parseAdditiveExpr();e=new u(c.RELATIONAL_EXPR,{operator:"<=",left:e,right:t})}else if(this.match(o.GT)){let t=this.parseAdditiveExpr();e=new u(c.RELATIONAL_EXPR,{operator:">",left:e,right:t})}else if(this.match(o.GTE)){let t=this.parseAdditiveExpr();e=new u(c.RELATIONAL_EXPR,{operator:">=",left:e,right:t})}else break;return e}parseAdditiveExpr(){let e=this.parseMultiplicativeExpr();for(;;)if(this.match(o.PLUS)){let t=this.parseMultiplicativeExpr();e=new u(c.ADDITIVE_EXPR,{operator:"+",left:e,right:t})}else if(this.match(o.MINUS)){let t=this.parseMultiplicativeExpr();e=new u(c.ADDITIVE_EXPR,{operator:"-",left:e,right:t})}else break;return e}parseMultiplicativeExpr(){let e=this.parseUnaryExpr();for(;;)if(this.match(o.STAR)){let t=this.parseUnaryExpr();e=new u(c.MULTIPLICATIVE_EXPR,{operator:"*",left:e,right:t})}else if(this.match(o.DIV)){let t=this.parseUnaryExpr();e=new u(c.MULTIPLICATIVE_EXPR,{operator:"div",left:e,right:t})}else if(this.match(o.MOD)){let t=this.parseUnaryExpr();e=new u(c.MULTIPLICATIVE_EXPR,{operator:"mod",left:e,right:t})}else break;return e}parseUnaryExpr(){if(this.match(o.MINUS)){let e=this.parseUnaryExpr();return new u(c.UNARY_EXPR,{operator:"-",operand:e})}return this.parseUnionExpr()}parseUnionExpr(){let e=this.parsePathExpr();for(;this.match(o.PIPE);){let t=this.parsePathExpr();e=new u(c.UNION_EXPR,{left:e,right:t})}return e}parsePathExpr(){if(this.check(o.SLASH)||this.check(o.DOUBLE_SLASH))return this.parseLocationPath();if(this.isStepStart())return this.parseLocationPath();let e=this.parseFilterExpr();if(this.check(o.SLASH)||this.check(o.DOUBLE_SLASH)){let t=[];for(;this.check(o.SLASH)||this.check(o.DOUBLE_SLASH);){let s=this.match(o.DOUBLE_SLASH);s||this.advance(),s&&t.push(new u(c.STEP,{axis:"descendant-or-self",nodeTest:new u(c.NODE_TYPE_TEST,{nodeType:"node"}),predicates:[]})),t.push(this.parseStep())}return new u(c.PATH_EXPR,{filter:e,steps:t})}return e}parseLocationPath(){let e=!1,t=[];for(this.match(o.DOUBLE_SLASH)?(e=!0,t.push(new u(c.STEP,{axis:"descendant-or-self",nodeTest:new u(c.NODE_TYPE_TEST,{nodeType:"node"}),predicates:[]})),!this.isAtEnd()&&!this.check(o.EOF)&&t.push(this.parseStep())):this.match(o.SLASH)?(e=!0,this.isStepStart()&&t.push(this.parseStep())):t.push(this.parseStep());this.check(o.SLASH)||this.check(o.DOUBLE_SLASH);){let s=this.match(o.DOUBLE_SLASH);s||this.advance(),s&&t.push(new u(c.STEP,{axis:"descendant-or-self",nodeTest:new u(c.NODE_TYPE_TEST,{nodeType:"node"}),predicates:[]})),t.push(this.parseStep())}return new u(c.LOCATION_PATH,{absolute:e,steps:t})}parseStep(){if(this.match(o.DOT))return new u(c.STEP,{axis:"self",nodeTest:new u(c.NODE_TYPE_TEST,{nodeType:"node"}),predicates:[]});if(this.match(o.DOUBLE_DOT))return new u(c.STEP,{axis:"parent",nodeTest:new u(c.NODE_TYPE_TEST,{nodeType:"node"}),predicates:[]});let e="child";this.match(o.AT)?e="attribute":this.check(o.AXIS)&&(e=this.advance().value,this.expect(o.DOUBLE_COLON));let t=this.parseNodeTest(),s=[];for(;this.check(o.LBRACKET);)s.push(this.parsePredicate());return new u(c.STEP,{axis:e,nodeTest:t,predicates:s})}parseNodeTest(){if(this.check(o.NODE_TYPE)){let e=this.advance().value;if(this.expect(o.LPAREN),e==="processing-instruction"&&this.check(o.LITERAL)){let t=this.advance().value;return this.expect(o.RPAREN),new u(c.PI_TEST,{name:t})}return this.expect(o.RPAREN),new u(c.NODE_TYPE_TEST,{nodeType:e})}return this.parseNameTest()}parseNameTest(){if(this.match(o.STAR))return new u(c.NAME_TEST,{name:"*",prefix:null});if(!this.check(o.NAME))throw new Error(`Expected name at position ${this.peek().position}`);let e=this.advance().value;if(this.match(o.COLON)){if(this.match(o.STAR))return new u(c.NAME_TEST,{name:"*",prefix:e});if(this.check(o.NAME)){let t=this.advance().value;return new u(c.NAME_TEST,{name:t,prefix:e})}throw new Error(`Expected name or * after : at position ${this.peek().position}`)}return new u(c.NAME_TEST,{name:e,prefix:null})}parsePredicate(){this.expect(o.LBRACKET);let e=this.parseExpr();return this.expect(o.RBRACKET),new u(c.PREDICATE,{expr:e})}parseFilterExpr(){let e=this.parsePrimaryExpr();for(;this.check(o.LBRACKET);){let t=this.parsePredicate();e=new u(c.PATH_EXPR,{filter:e,predicates:[t]})}return e}parsePrimaryExpr(){if(this.match(o.DOLLAR)){if(!this.check(o.NAME))throw new Error(`Expected variable name at position ${this.peek().position}`);let e=this.advance().value,t=null;if(this.match(o.COLON)){if(t=e,!this.check(o.NAME))throw new Error(`Expected local name at position ${this.peek().position}`);let s=this.advance().value;return new u(c.VARIABLE_REF,{name:s,prefix:t})}return new u(c.VARIABLE_REF,{name:e,prefix:t})}if(this.match(o.LPAREN)){let e=this.parseExpr();return this.expect(o.RPAREN),e}if(this.check(o.LITERAL))return new u(c.LITERAL,{value:this.advance().value});if(this.check(o.NUMBER))return new u(c.NUMBER,{value:this.advance().value});if(this.check(o.FUNCTION))return this.parseFunctionCall();throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().position}`)}parseFunctionCall(){let e=this.advance().value;return this.parseFunctionCallArgs(e,null)}parseFunctionCallArgs(e,t){this.expect(o.LPAREN);let s=[];if(!this.check(o.RPAREN))for(s.push(this.parseExpr());this.match(o.COMMA);)s.push(this.parseExpr());return this.expect(o.RPAREN),new u(c.FUNCTION_CALL,{name:e,prefix:t,args:s})}isStepStart(){let e=this.peek().type;return e===o.NAME||e===o.STAR||e===o.AT||e===o.DOT||e===o.DOUBLE_DOT||e===o.AXIS||e===o.NODE_TYPE}peek(){return this.tokens[this.position]}advance(){return this.isAtEnd()?this.tokens[this.position]:this.tokens[this.position++]}check(e){return this.isAtEnd()?!1:this.peek().type===e}match(e){return this.check(e)?(this.advance(),!0):!1}expect(e){if(!this.check(e))throw new Error(`Expected ${e} but got ${this.peek().type} at position ${this.peek().position}`);return this.advance()}isAtEnd(){return this.peek().type===o.EOF}};function T(m){let e=x(m);return new w(e).parse()}var R={ANY_TYPE:0,NUMBER_TYPE:1,STRING_TYPE:2,BOOLEAN_TYPE:3,UNORDERED_NODE_ITERATOR_TYPE:4,ORDERED_NODE_ITERATOR_TYPE:5,UNORDERED_NODE_SNAPSHOT_TYPE:6,ORDERED_NODE_SNAPSHOT_TYPE:7,ANY_UNORDERED_NODE_TYPE:8,FIRST_ORDERED_NODE_TYPE:9},P={MAX_RECURSION_DEPTH:100,MAX_RESULT_SIZE:1e4,MAX_STRING_LENGTH:1e6},C=Object.freeze(["__proto__","constructor","prototype","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__"]),E=class m{constructor(e,t=1,s=1,r={},i={}){this.node=e,this.position=t,this.size=s,this.variables=r,this.namespaces=i}clone(e={}){return new m(e.node??this.node,e.position??this.position,e.size??this.size,e.variables??this.variables,e.namespaces??this.namespaces)}},g=class{constructor(e={}){this.functions=this.initCoreFunctions(),this.maxRecursionDepth=e.maxRecursionDepth??P.MAX_RECURSION_DEPTH,this.maxResultSize=e.maxResultSize??P.MAX_RESULT_SIZE,this.maxStringLength=e.maxStringLength??P.MAX_STRING_LENGTH,this.recursionDepth=0}evaluate(e,t){if(!e||typeof e!="object")throw new Error("Invalid AST: expected object");if(!e.type)throw new Error("Invalid AST: missing type property");if(this.recursionDepth++,this.recursionDepth>this.maxRecursionDepth)throw this.recursionDepth=0,new Error(`Maximum recursion depth exceeded (${this.maxRecursionDepth})`);try{return this.evaluateInternal(e,t)}finally{this.recursionDepth--}}evaluateInternal(e,t){switch(e.type){case c.OR_EXPR:return this.evalOrExpr(e,t);case c.AND_EXPR:return this.evalAndExpr(e,t);case c.EQUALITY_EXPR:return this.evalEqualityExpr(e,t);case c.RELATIONAL_EXPR:return this.evalRelationalExpr(e,t);case c.ADDITIVE_EXPR:return this.evalAdditiveExpr(e,t);case c.MULTIPLICATIVE_EXPR:return this.evalMultiplicativeExpr(e,t);case c.UNARY_EXPR:return this.evalUnaryExpr(e,t);case c.UNION_EXPR:return this.evalUnionExpr(e,t);case c.PATH_EXPR:return this.evalPathExpr(e,t);case c.LOCATION_PATH:return this.evalLocationPath(e,t);case c.VARIABLE_REF:return this.evalVariableRef(e,t);case c.LITERAL:return this.validateString(e.value);case c.NUMBER:return e.value;case c.FUNCTION_CALL:return this.evalFunctionCall(e,t);default:throw new Error(`Unknown AST node type: ${String(e.type)}`)}}validateString(e){if(typeof e=="string"&&e.length>this.maxStringLength)throw new Error(`String exceeds maximum length (${this.maxStringLength})`);return e}validateResultSize(e){if(Array.isArray(e)&&e.length>this.maxResultSize)throw new Error(`Result set exceeds maximum size (${this.maxResultSize})`);return e}evalOrExpr(e,t){return this.toBoolean(this.evaluate(e.left,t))||this.toBoolean(this.evaluate(e.right,t))}evalAndExpr(e,t){return this.toBoolean(this.evaluate(e.left,t))&&this.toBoolean(this.evaluate(e.right,t))}evalEqualityExpr(e,t){let s=this.evaluate(e.left,t),r=this.evaluate(e.right,t),i=this.compareValues(s,r,"=");return e.operator==="="?i:!i}evalRelationalExpr(e,t){let s=this.evaluate(e.left,t),r=this.evaluate(e.right,t);return this.compareValues(s,r,e.operator)}evalAdditiveExpr(e,t){let s=this.toNumber(this.evaluate(e.left,t)),r=this.toNumber(this.evaluate(e.right,t));return e.operator==="+"?s+r:s-r}evalMultiplicativeExpr(e,t){let s=this.toNumber(this.evaluate(e.left,t)),r=this.toNumber(this.evaluate(e.right,t));switch(e.operator){case"*":return s*r;case"div":return s/r;case"mod":return s%r;default:throw new Error(`Unknown multiplicative operator: ${e.operator}`)}}evalUnaryExpr(e,t){return-this.toNumber(this.evaluate(e.operand,t))}evalUnionExpr(e,t){let s=this.evaluate(e.left,t),r=this.evaluate(e.right,t),i=Array.isArray(s)?s:[s],n=Array.isArray(r)?r:[r],a=new Set,l=[];for(let h of[...i,...n])a.has(h)||(a.add(h),l.push(h));return this.validateResultSize(l),this.sortByDocumentOrder(l)}evalPathExpr(e,t){if(e.filter){let s=this.evaluate(e.filter,t);if(e.predicates)for(let r of e.predicates)s=this.filterByPredicate(s,r,t);if(e.steps)for(let r of e.steps)s=this.evalStepOnNodes(r,s,t);return s}return[]}evalLocationPath(e,t){let s;e.absolute?s=[t.node.ownerDocument||t.node]:s=[t.node];for(let r of e.steps)s=this.evalStepOnNodes(r,s,t),this.validateResultSize(s);return s}evalStepOnNodes(e,t,s){let r=Array.isArray(t)?t:[t],i=[];for(let a of r){let l=this.evalStep(e,s.clone({node:a}));i=i.concat(l),i.length>this.maxResultSize*2&&this.validateResultSize(i)}let n=[...new Set(i)];return this.validateResultSize(n),this.sortByDocumentOrder(n)}evalStep(e,t){let s=this.getAxisNodes(e.axis,t.node);s=s.filter(r=>this.matchNodeTest(e.nodeTest,r,t));for(let r of e.predicates)s=this.filterByPredicate(s,r,t);return s}getAxisNodes(e,t){switch(e){case"child":return Array.from(t.childNodes||[]);case"parent":return t.parentNode?[t.parentNode]:[];case"self":return[t];case"descendant":return this.getDescendants(t,!1);case"descendant-or-self":return this.getDescendants(t,!0);case"ancestor":return this.getAncestors(t,!1);case"ancestor-or-self":return this.getAncestors(t,!0);case"following-sibling":return this.getFollowingSiblings(t);case"preceding-sibling":return this.getPrecedingSiblings(t);case"following":return this.getFollowing(t);case"preceding":return this.getPreceding(t);case"attribute":return t.attributes?Array.from(t.attributes):[];case"namespace":return[];default:throw new Error(`Unknown axis: ${e}`)}}getDescendants(e,t){let s=t?[e]:[],r=Array.from(e.childNodes||[]).reverse();for(;r.length>0;){let i=r.pop();if(s.push(i),i.childNodes)for(let n=i.childNodes.length-1;n>=0;n--)r.push(i.childNodes[n])}return s}getAncestors(e,t){let s=t?[e]:[],r=e.parentNode;for(;r;)s.push(r),r=r.parentNode;return s}getFollowingSiblings(e){let t=[];if(!e)return t;let s=e.nextSibling;for(;s;)t.push(s),s=s.nextSibling;return t}getPrecedingSiblings(e){let t=[];if(!e)return t;let s=e.previousSibling;for(;s;)t.push(s),s=s.previousSibling;return t.reverse()}getFollowing(e){let t=[],s=e;for(;s;)s.nextSibling?(s=s.nextSibling,t.push(s),t.push(...this.getDescendants(s,!1))):s=s.parentNode;return t}getPreceding(e){let t=[],s=e;for(;s;)if(s.previousSibling){s=s.previousSibling;let r=this.getDescendants(s,!1);t.unshift(...r.reverse()),t.unshift(s)}else s=s.parentNode,s&&s.nodeType;return t}matchNodeTest(e,t,s){switch(e.type){case c.NAME_TEST:return this.matchNameTest(e,t,s);case c.NODE_TYPE_TEST:return this.matchNodeTypeTest(e.nodeType,t);case c.PI_TEST:return t.nodeType===7&&t.nodeName===e.name;default:return!1}}matchNameTest(e,t,s){if(t.nodeType!==1&&t.nodeType!==2)return!1;let r=e.name,i=e.prefix;if(r==="*"&&!i)return!0;let n=t.localName||t.nodeName,a=t.namespaceURI||null;if(r==="*"&&i){let h=s.namespaces[i];return a===h}if(!i){let h=t.ownerDocument;return h&&h.contentType==="text/html"&&t.nodeType===1?n.toLowerCase()===r.toLowerCase():n===r}let l=s.namespaces[i];return n===r&&a===l}matchNodeTypeTest(e,t){switch(e){case"node":return!0;case"text":return t.nodeType===3;case"comment":return t.nodeType===8;case"processing-instruction":return t.nodeType===7;default:return!1}}filterByPredicate(e,t,s){let r=[],i=Array.isArray(e)?e:[e],n=i.length;for(let a=0;a<i.length;a++){let l=i[a],h=s.clone({node:l,position:a+1,size:n}),p=this.evaluate(t.expr,h);typeof p=="number"?p===a+1&&r.push(l):this.toBoolean(p)&&r.push(l)}return r}evalVariableRef(e,t){let s=e.prefix?`${e.prefix}:${e.name}`:e.name;if(C.includes(s)||C.includes(e.name))throw new Error(`Forbidden variable name: $${s}`);if(!Object.prototype.hasOwnProperty.call(t.variables,s))throw new Error(`Undefined variable: $${s}`);return t.variables[s]}evalFunctionCall(e,t){let s=e.prefix?`${e.prefix}:${e.name}`:e.name,r=this.functions[s];if(!r)throw new Error(`Unknown function: ${s}`);return r.call(this,e.args,t)}toBoolean(e){return typeof e=="boolean"?e:typeof e=="number"?e!==0&&!isNaN(e):typeof e=="string"||Array.isArray(e)?e.length>0:e&&e.nodeType?!0:!!e}toNumber(e){if(typeof e=="number")return e;if(typeof e=="boolean")return e?1:0;if(typeof e=="string"){let t=e.trim();return t===""?NaN:Number(t)}return Array.isArray(e)?this.toNumber(this.toString(e)):e&&e.nodeType?this.toNumber(this.getStringValue(e)):NaN}toString(e){return typeof e=="string"?e:typeof e=="number"?isNaN(e)?"NaN":e===1/0?"Infinity":e===-1/0?"-Infinity":e===0?"0":String(e):typeof e=="boolean"?e?"true":"false":Array.isArray(e)?e.length===0?"":this.getStringValue(e[0]):e&&e.nodeType?this.getStringValue(e):String(e)}getStringValue(e){if(!e)return"";switch(e.nodeType){case 1:case 9:case 11:{let t="",s=r=>{if(r.nodeType===3)t+=r.nodeValue||"";else if(r.childNodes)for(let i of r.childNodes)s(i)};return s(e),t}case 2:case 3:case 4:case 7:case 8:return e.nodeValue||"";default:return""}}compareValues(e,t,s){let r=Array.isArray(e),i=Array.isArray(t);if(r&&i){for(let n of e)for(let a of t)if(this.comparePrimitive(this.getStringValue(n),this.getStringValue(a),s))return!0;return!1}if(r){for(let n of e)if(this.comparePrimitive(this.getStringValue(n),t,s))return!0;return!1}if(i){for(let n of t)if(this.comparePrimitive(e,this.getStringValue(n),s))return!0;return!1}return this.comparePrimitive(e,t,s)}comparePrimitive(e,t,s){if(s==="="||s==="!="){if(typeof e=="boolean"||typeof t=="boolean"){let a=this.toBoolean(e)===this.toBoolean(t);return s==="="?a:!a}if(typeof e=="number"||typeof t=="number"){let a=this.toNumber(e)===this.toNumber(t);return s==="="?a:!a}let n=this.toString(e)===this.toString(t);return s==="="?n:!n}let r=this.toNumber(e),i=this.toNumber(t);switch(s){case"<":return r<i;case"<=":return r<=i;case">":return r>i;case">=":return r>=i;default:throw new Error(`Unknown comparison operator: ${s}`)}}sortByDocumentOrder(e){return e.length<=1?e:e.sort((t,s)=>{if(t===s)return 0;let r=t.compareDocumentPosition?t.compareDocumentPosition(s):this.compareDocumentPositionFallback(t,s);return r&4?-1:r&2?1:0})}compareDocumentPositionFallback(e,t){let s=n=>{let a=[],l=n;for(;l;){if(l.parentNode){let h=Array.from(l.parentNode.childNodes);a.unshift(h.indexOf(l))}l=l.parentNode}return a},r=s(e),i=s(t);for(let n=0;n<Math.min(r.length,i.length);n++){if(r[n]<i[n])return 4;if(r[n]>i[n])return 2}return r.length<i.length?4:2}initCoreFunctions(){return{last:(e,t)=>t.size,position:(e,t)=>t.position,count:(e,t)=>{let s=this.evaluate(e[0],t);return Array.isArray(s)?s.length:1},id:(e,t)=>{let s=this.toString(this.evaluate(e[0],t)),r=t.node.ownerDocument||t.node,i=s.split(/\s+/).filter(a=>a),n=[];for(let a of i){let l=r.getElementById(a);l&&n.push(l)}return n},"local-name":(e,t)=>{let s;if(e.length===0)s=t.node;else{let r=this.evaluate(e[0],t);s=Array.isArray(r)?r[0]:r}return s&&(s.localName||s.nodeName)||""},"namespace-uri":(e,t)=>{let s;if(e.length===0)s=t.node;else{let r=this.evaluate(e[0],t);s=Array.isArray(r)?r[0]:r}return s&&s.namespaceURI||""},name:(e,t)=>{let s;if(e.length===0)s=t.node;else{let r=this.evaluate(e[0],t);s=Array.isArray(r)?r[0]:r}return s&&s.nodeName||""},string:(e,t)=>e.length===0?this.toString([t.node]):this.toString(this.evaluate(e[0],t)),concat:(e,t)=>e.map(s=>this.toString(this.evaluate(s,t))).join(""),"starts-with":(e,t)=>{let s=this.toString(this.evaluate(e[0],t)),r=this.toString(this.evaluate(e[1],t));return s.startsWith(r)},contains:(e,t)=>{let s=this.toString(this.evaluate(e[0],t)),r=this.toString(this.evaluate(e[1],t));return s.includes(r)},"substring-before":(e,t)=>{let s=this.toString(this.evaluate(e[0],t)),r=this.toString(this.evaluate(e[1],t)),i=s.indexOf(r);return i===-1?"":s.substring(0,i)},"substring-after":(e,t)=>{let s=this.toString(this.evaluate(e[0],t)),r=this.toString(this.evaluate(e[1],t)),i=s.indexOf(r);return i===-1?"":s.substring(i+r.length)},substring:(e,t)=>{let s=this.toString(this.evaluate(e[0],t)),r=Math.round(this.toNumber(this.evaluate(e[1],t))),i;return e.length>2&&(i=Math.round(this.toNumber(this.evaluate(e[2],t)))),r=r-1,isNaN(r)?"":(r<0&&(i!==void 0&&(i=i+r),r=0),i!==void 0?isNaN(i)||i<=0?"":s.substring(r,r+i):s.substring(r))},"string-length":(e,t)=>(e.length===0?this.toString([t.node]):this.toString(this.evaluate(e[0],t))).length,"normalize-space":(e,t)=>(e.length===0?this.toString([t.node]):this.toString(this.evaluate(e[0],t))).trim().replace(/\s+/g," "),translate:(e,t)=>{let s=this.toString(this.evaluate(e[0],t)),r=this.toString(this.evaluate(e[1],t)),i=this.toString(this.evaluate(e[2],t)),n="";for(let a of s){let l=r.indexOf(a);l===-1?n+=a:l<i.length&&(n+=i[l])}return n},boolean:(e,t)=>this.toBoolean(this.evaluate(e[0],t)),not:(e,t)=>!this.toBoolean(this.evaluate(e[0],t)),true:()=>!0,false:()=>!1,lang:(e,t)=>{let s=this.toString(this.evaluate(e[0],t)).toLowerCase(),r=t.node;for(;r&&r.nodeType===1;){let i=r.getAttribute("xml:lang")||r.getAttribute("lang");if(i){let n=i.toLowerCase();return n===s||n.startsWith(s+"-")}r=r.parentNode}return!1},number:(e,t)=>e.length===0?this.toNumber([t.node]):this.toNumber(this.evaluate(e[0],t)),sum:(e,t)=>{let s=this.evaluate(e[0],t);return Array.isArray(s)?s.reduce((r,i)=>r+this.toNumber(this.getStringValue(i)),0):NaN},floor:(e,t)=>Math.floor(this.toNumber(this.evaluate(e[0],t))),ceiling:(e,t)=>Math.ceil(this.toNumber(this.evaluate(e[0],t))),round:(e,t)=>{let s=this.toNumber(this.evaluate(e[0],t));return isNaN(s)?NaN:s===-.5?-0:Math.round(s)}}}};var N="http://www.w3.org/1999/XSL/Transform",S=class m{constructor(e={}){this.currentNode=e.currentNode,this.currentNodeList=e.currentNodeList||[],this.position=e.position||1,this.variables={...e.variables},this.parameters={...e.parameters},this.outputDocument=e.outputDocument,this.stylesheet=e.stylesheet,this.namespaces={...e.namespaces},this.templates=e.templates||[],this.keys=e.keys||{},this.decimalFormats=e.decimalFormats||{},this.outputMethod=e.outputMethod||"xml",this.xpathEvaluator=e.xpathEvaluator||new g}clone(e={}){return new m({currentNode:e.currentNode??this.currentNode,currentNodeList:e.currentNodeList??this.currentNodeList,position:e.position??this.position,variables:e.variables?{...this.variables,...e.variables}:{...this.variables},parameters:e.parameters?{...this.parameters,...e.parameters}:{...this.parameters},outputDocument:this.outputDocument,stylesheet:this.stylesheet,namespaces:e.namespaces?{...this.namespaces,...e.namespaces}:{...this.namespaces},templates:this.templates,keys:this.keys,decimalFormats:this.decimalFormats,outputMethod:this.outputMethod,xpathEvaluator:this.xpathEvaluator})}getVariable(e){if(e in this.variables)return this.variables[e];if(e in this.parameters)return this.parameters[e];throw new Error(`Undefined variable: $${e}`)}setVariable(e,t){this.variables[e]=t}},A=class{constructor(e={}){this.xpathEvaluator=new g,this.templates=[],this.keys={},this.globalVariables={},this.globalParameters={},this.outputSettings={method:"xml",encoding:"UTF-8",indent:"no",omitXmlDeclaration:"no",doctypePublic:null,doctypeSystem:null,mediaType:null,cdataSectionElements:[]},this.namespaces={},this.decimalFormats={},this.stylesheetDoc=null,this.attributeSets={},this.namespaceAliases={},this.stripSpace=[],this.preserveSpace=[],this.stylesheetLoader=e.stylesheetLoader||null,this.currentImportPrecedence=0,this.processedStylesheets=new Set,this.baseUri=e.baseUri||""}setStylesheetLoader(e){this.stylesheetLoader=e}resolveUri(e,t){if(!t||e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/"))return e;let s=t.lastIndexOf("/");return(s>=0?t.substring(0,s+1):"")+e}loadStylesheet(e,t){if(!this.stylesheetLoader)throw new Error(`Cannot load stylesheet "${e}": no stylesheetLoader configured. Use engine.setStylesheetLoader(fn) to provide a loader function.`);let s=this.resolveUri(e,t);return{document:this.stylesheetLoader(s,t),uri:s}}parseXmlString(e){if(typeof DOMParser<"u"){let s=new DOMParser().parseFromString(e,"application/xml"),r=s.querySelector("parsererror");if(r)throw new Error(`XML parse error: ${r.textContent}`);return s}throw new Error("XML parsing not available in this environment")}importStylesheet(e,t){let s=this.stylesheetDoc===null;s&&(this.stylesheetDoc=e.ownerDocument||e,t&&(this.baseUri=t,this.processedStylesheets.add(t)));let r=e.documentElement||e;if(!this.isXsltElement(r,"stylesheet")&&!this.isXsltElement(r,"transform")){if(r.getAttribute&&r.getAttribute("xsl:version")){this.processLiteralResultStylesheet(r);return}throw new Error("Invalid XSLT stylesheet: root element must be xsl:stylesheet or xsl:transform")}this.collectNamespaces(r);let i=[],n=[];for(let a of r.childNodes)a.nodeType===1&&(this.isXsltElement(a,"import")?i.push(a):n.push(a));for(let a of i)this.processImport(a,t||this.baseUri);for(let a of n)this.isXsltElement(a,"template")?this.registerTemplate(a):this.isXsltElement(a,"output")?this.processOutput(a):this.isXsltElement(a,"variable")?this.processGlobalVariable(a):this.isXsltElement(a,"param")?this.processGlobalParam(a):this.isXsltElement(a,"key")?this.processKey(a):this.isXsltElement(a,"decimal-format")?this.processDecimalFormat(a):this.isXsltElement(a,"namespace-alias")?this.processNamespaceAlias(a):this.isXsltElement(a,"attribute-set")?this.processAttributeSet(a):this.isXsltElement(a,"strip-space")?this.processStripSpace(a):this.isXsltElement(a,"preserve-space")?this.processPreserveSpace(a):this.isXsltElement(a,"include")&&this.processInclude(a,t||this.baseUri);s&&this.currentImportPrecedence++}processInclude(e,t){let s=e.getAttribute("href");if(!s)throw new Error("xsl:include requires an href attribute");let r=this.resolveUri(s,t);if(this.processedStylesheets.has(r))throw new Error(`Circular stylesheet reference detected: ${r}`);this.processedStylesheets.add(r);try{let{document:i}=this.loadStylesheet(s,t),n=i;typeof i=="string"&&(n=this.parseXmlString(i));let a=this.currentImportPrecedence;this.processIncludedStylesheet(n,r),this.currentImportPrecedence=a}catch(i){throw new Error(`Failed to include stylesheet "${s}": ${i.message}`)}}processImport(e,t){let s=e.getAttribute("href");if(!s)throw new Error("xsl:import requires an href attribute");let r=this.resolveUri(s,t);if(this.processedStylesheets.has(r))throw new Error(`Circular stylesheet reference detected: ${r}`);this.processedStylesheets.add(r);try{let{document:i}=this.loadStylesheet(s,t),n=i;typeof i=="string"&&(n=this.parseXmlString(i)),this.processIncludedStylesheet(n,r),this.currentImportPrecedence++}catch(i){throw new Error(`Failed to import stylesheet "${s}": ${i.message}`)}}processIncludedStylesheet(e,t){let s=e.documentElement||e;if(!this.isXsltElement(s,"stylesheet")&&!this.isXsltElement(s,"transform"))throw new Error("Included/imported document is not a valid XSLT stylesheet");this.collectNamespaces(s);let r=[],i=[];for(let n of s.childNodes)n.nodeType===1&&(this.isXsltElement(n,"import")?r.push(n):i.push(n));for(let n of r)this.processImport(n,t);for(let n of i)this.isXsltElement(n,"template")?this.registerTemplate(n):this.isXsltElement(n,"output")?this.processOutput(n):this.isXsltElement(n,"variable")?this.processGlobalVariable(n):this.isXsltElement(n,"param")?this.processGlobalParam(n):this.isXsltElement(n,"key")?this.processKey(n):this.isXsltElement(n,"decimal-format")?this.processDecimalFormat(n):this.isXsltElement(n,"namespace-alias")?this.processNamespaceAlias(n):this.isXsltElement(n,"attribute-set")?this.processAttributeSet(n):this.isXsltElement(n,"strip-space")?this.processStripSpace(n):this.isXsltElement(n,"preserve-space")?this.processPreserveSpace(n):this.isXsltElement(n,"include")&&this.processInclude(n,t)}processLiteralResultStylesheet(e){this.templates.push({match:"/",name:null,mode:null,priority:.5,node:e})}collectNamespaces(e){if(e.attributes)for(let t of e.attributes)if(t.name.startsWith("xmlns:")){let s=t.name.substring(6);t.value!==N&&(this.namespaces[s]=t.value)}else t.name==="xmlns"&&t.value!==N&&(this.namespaces[""]=t.value)}registerTemplate(e){let t=e.getAttribute("match"),s=e.getAttribute("name"),r=e.getAttribute("mode")||null,i=e.getAttribute("priority"),n=i?parseFloat(i):this.calculatePriority(t);this.templates.push({match:t,name:s,mode:r,priority:n,importPrecedence:this.currentImportPrecedence,node:e})}calculatePriority(e){return e?e==="*"||e==="node()"||e==="text()"||e==="comment()"||e==="processing-instruction()"?-.5:e.includes(":*")?-.25:/^[a-zA-Z_][\w.-]*$/.test(e)?0:.5:.5}processOutput(e){let t=e.getAttribute("method");t&&(this.outputSettings.method=t);let s=e.getAttribute("encoding");s&&(this.outputSettings.encoding=s);let r=e.getAttribute("indent");r&&(this.outputSettings.indent=r);let i=e.getAttribute("omit-xml-declaration");i&&(this.outputSettings.omitXmlDeclaration=i);let n=e.getAttribute("doctype-public");n&&(this.outputSettings.doctypePublic=n);let a=e.getAttribute("doctype-system");a&&(this.outputSettings.doctypeSystem=a);let l=e.getAttribute("media-type");l&&(this.outputSettings.mediaType=l);let h=e.getAttribute("cdata-section-elements");h&&(this.outputSettings.cdataSectionElements=h.split(/\s+/).filter(Boolean))}processGlobalVariable(e){let t=e.getAttribute("name"),s=e.getAttribute("select");this.globalVariables[t]={node:e,select:s}}processGlobalParam(e){let t=e.getAttribute("name"),s=e.getAttribute("select");this.globalParameters[t]={node:e,select:s}}processKey(e){let t=e.getAttribute("name"),s=e.getAttribute("match"),r=e.getAttribute("use");this.keys[t]={match:s,use:r}}processDecimalFormat(e){let t=e.getAttribute("name")||"";this.decimalFormats[t]={decimalSeparator:e.getAttribute("decimal-separator")||".",groupingSeparator:e.getAttribute("grouping-separator")||",",percent:e.getAttribute("percent")||"%",perMille:e.getAttribute("per-mille")||"\u2030",zeroDigit:e.getAttribute("zero-digit")||"0",digit:e.getAttribute("digit")||"#",patternSeparator:e.getAttribute("pattern-separator")||";",infinity:e.getAttribute("infinity")||"Infinity",nan:e.getAttribute("NaN")||"NaN",minusSign:e.getAttribute("minus-sign")||"-"}}processNamespaceAlias(e){let t=e.getAttribute("stylesheet-prefix"),s=e.getAttribute("result-prefix");this.namespaceAliases[t]=s}processAttributeSet(e){let t=e.getAttribute("name"),s=e.getAttribute("use-attribute-sets");this.attributeSets[t]={node:e,useAttributeSets:s?s.split(/\s+/).filter(Boolean):[]}}processStripSpace(e){let t=e.getAttribute("elements");t&&this.stripSpace.push(...t.split(/\s+/).filter(Boolean))}processPreserveSpace(e){let t=e.getAttribute("elements");t&&this.preserveSpace.push(...t.split(/\s+/).filter(Boolean))}transform(e,t){let s=t||(typeof document<"u"?document:null);if(!s)throw new Error("No output document available");let r=new S({currentNode:e.documentElement||e,currentNodeList:[e.documentElement||e],position:1,outputDocument:s,stylesheet:this.stylesheetDoc,namespaces:{...this.namespaces},templates:this.templates,keys:this.keys,decimalFormats:this.decimalFormats,outputMethod:this.outputSettings.method,xpathEvaluator:this.xpathEvaluator});for(let[n,a]of Object.entries(this.globalParameters))n in r.parameters||(r.parameters[n]=this.evaluateVariable(a,r));for(let[n,a]of Object.entries(this.globalVariables))r.variables[n]=this.evaluateVariable(a,r);let i=s.createDocumentFragment();return this.applyTemplates([e.documentElement||e],null,r,i),i}transformToDocument(e){let t=this.createDocument(),s=this.transform(e,t);for(;s.firstChild;)t.appendChild(s.firstChild);return t}createDocument(){if(typeof document<"u")return document.implementation.createDocument(null,null,null);throw new Error("Document creation not available in this environment")}evaluateVariable(e,t){if(e.select)return this.evaluateXPath(e.select,t);let s=t.outputDocument.createDocumentFragment();return this.processChildren(e.node,t,s),s}applyTemplates(e,t,s,r){let i=Array.isArray(e)?e:[e];for(let n=0;n<i.length;n++){let a=i[n],l=this.findMatchingTemplate(a,t,s);if(l){let h=s.clone({currentNode:a,currentNodeList:i,position:n+1});this.processTemplate(l.node,h,r)}else this.applyBuiltinTemplate(a,t,s,r)}}findMatchingTemplate(e,t,s){let r=null,i=-1/0,n=-1/0;for(let a of this.templates)if(a.mode===t&&a.match&&this.matchesPattern(e,a.match,s)){let l=a.priority,h=a.importPrecedence||0;(h>n||h===n&&l>i)&&(r=a,i=l,n=h)}return r}matchesPattern(e,t,s){let r=this.splitUnionPattern(t);for(let i of r)if(this.matchesSinglePattern(e,i.trim(),s))return!0;return!1}splitUnionPattern(e){let t=[],s="",r=0,i=!1,n="";for(let a=0;a<e.length;a++){let l=e[a];i?(s+=l,l===n&&(i=!1)):l==='"'||l==="'"?(i=!0,n=l,s+=l):l==="["?(r++,s+=l):l==="]"?(r--,s+=l):l==="|"&&r===0?(t.push(s),s=""):s+=l}return s&&t.push(s),t}matchesSinglePattern(e,t,s){var r;try{if(t==="/")return e.nodeType===9||e===((r=e.ownerDocument)==null?void 0:r.documentElement);let i=T(t);if(t.startsWith("/")){let h=e.ownerDocument||e,p=new E(h,1,1,{...s.variables,...s.parameters},s.namespaces),d=this.xpathEvaluator.evaluate(i,p);return(Array.isArray(d)?d:[d]).includes(e)}if(e.parentNode){let h=new E(e.parentNode,1,1,{...s.variables,...s.parameters},s.namespaces),p=this.xpathEvaluator.evaluate(i,h);return(Array.isArray(p)?p:[p]).includes(e)}let n=new E(e,1,1,{...s.variables,...s.parameters},s.namespaces),a=this.xpathEvaluator.evaluate(i,n);return(Array.isArray(a)?a:[a]).includes(e)}catch{return!1}}applyBuiltinTemplate(e,t,s,r){switch(e.nodeType){case 1:case 9:case 11:this.applyTemplates(Array.from(e.childNodes),t,s,r);break;case 3:case 4:{let i=s.outputDocument.createTextNode(e.nodeValue||"");r.appendChild(i);break}case 2:{let i=s.outputDocument.createTextNode(e.nodeValue||"");r.appendChild(i);break}}}processTemplate(e,t,s){let r=t.clone();for(let i of e.childNodes)if(i.nodeType===1&&this.isXsltElement(i,"param")){let n=i.getAttribute("name");n in r.parameters||(r.parameters[n]=this.evaluateVariable({node:i,select:i.getAttribute("select")},r))}this.processChildren(e,r,s)}processChildren(e,t,s){for(let r of e.childNodes)this.processNode(r,t,s)}processNode(e,t,s){switch(e.nodeType){case 1:this.processElement(e,t,s);break;case 3:case 4:{let r=e.nodeValue;if(r&&(r.trim()||this.shouldPreserveSpace(e))){let i=t.outputDocument.createTextNode(r);s.appendChild(i)}break}}}shouldPreserveSpace(e){let t=e.parentNode;for(;t&&t.nodeType===1;){let s=t.getAttribute("xml:space");if(s==="preserve")return!0;if(s==="default")return!1;t=t.parentNode}return!1}processElement(e,t,s){this.isXsltNamespace(e)?this.processXsltElement(e,t,s):this.processLiteralResultElement(e,t,s)}processXsltElement(e,t,s){let r=e.localName||e.nodeName.replace(/^xsl:/,"");switch(r){case"apply-templates":this.xslApplyTemplates(e,t,s);break;case"call-template":this.xslCallTemplate(e,t,s);break;case"value-of":this.xslValueOf(e,t,s);break;case"text":this.xslText(e,t,s);break;case"element":this.xslElement(e,t,s);break;case"attribute":this.xslAttribute(e,t,s);break;case"if":this.xslIf(e,t,s);break;case"choose":this.xslChoose(e,t,s);break;case"for-each":this.xslForEach(e,t,s);break;case"copy":this.xslCopy(e,t,s);break;case"copy-of":this.xslCopyOf(e,t,s);break;case"variable":this.xslVariable(e,t,s);break;case"param":break;case"comment":this.xslComment(e,t,s);break;case"processing-instruction":this.xslProcessingInstruction(e,t,s);break;case"number":this.xslNumber(e,t,s);break;case"sort":break;case"with-param":break;case"message":this.xslMessage(e,t,s);break;case"fallback":break;default:console.warn(`Unknown XSLT element: ${r}`)}}processLiteralResultElement(e,t,s){let r,i=e.namespaceURI,n=e.nodeName,a=i;if(i){for(let[l,h]of Object.entries(this.namespaceAliases))if(this.namespaces[l]===i){a=this.namespaces[h]||h;break}}if(a&&t.outputDocument.createElementNS?r=t.outputDocument.createElementNS(a,n):r=t.outputDocument.createElement(n),e.attributes)for(let l of e.attributes){if(l.namespaceURI===N||l.name.startsWith("xmlns"))continue;let h=this.processAttributeValueTemplate(l.value,t);r.setAttribute(l.name,h)}this.processChildren(e,t,r),s.appendChild(r)}processAttributeValueTemplate(e,t){if(!e.includes("{"))return e;let s="",r=0;for(;r<e.length;)if(e[r]==="{")if(e[r+1]==="{")s+="{",r+=2;else{let i=1,n=r+1;for(;n<e.length&&i>0;)e[n]==="{"?i++:e[n]==="}"&&i--,n++;let a=e.substring(r+1,n-1),l=this.evaluateXPath(a,t);s+=this.xpathEvaluator.toString(l),r=n}else if(e[r]==="}")if(e[r+1]==="}")s+="}",r+=2;else throw new Error("Unmatched } in attribute value template");else s+=e[r],r++;return s}xslApplyTemplates(e,t,s){let r=e.getAttribute("select")||"node()",i=e.getAttribute("mode")||null,n=this.evaluateXPath(r,t);Array.isArray(n)||(n=n?[n]:[]);let a=[];for(let p of e.childNodes)p.nodeType===1&&this.isXsltElement(p,"sort")&&a.push({select:p.getAttribute("select")||".",order:p.getAttribute("order")||"ascending",dataType:p.getAttribute("data-type")||"text",caseOrder:p.getAttribute("case-order")||"upper-first",lang:p.getAttribute("lang")});a.length>0&&(n=this.sortNodes(n,a,t));let l={};for(let p of e.childNodes)if(p.nodeType===1&&this.isXsltElement(p,"with-param")){let d=p.getAttribute("name"),L=p.getAttribute("select");if(L)l[d]=this.evaluateXPath(L,t);else{let X=t.outputDocument.createDocumentFragment();this.processChildren(p,t,X),l[d]=X}}let h=t.clone({parameters:{...t.parameters,...l}});this.applyTemplates(n,i,h,s)}xslCallTemplate(e,t,s){let r=e.getAttribute("name"),i=this.templates.find(l=>l.name===r);if(!i)throw new Error(`Template not found: ${r}`);let n={};for(let l of e.childNodes)if(l.nodeType===1&&this.isXsltElement(l,"with-param")){let h=l.getAttribute("name"),p=l.getAttribute("select");if(p)n[h]=this.evaluateXPath(p,t);else{let d=t.outputDocument.createDocumentFragment();this.processChildren(l,t,d),n[h]=d}}let a=t.clone({parameters:{...t.parameters,...n}});this.processTemplate(i.node,a,s)}xslValueOf(e,t,s){let r=e.getAttribute("select"),i=e.getAttribute("disable-output-escaping")==="yes",n=this.evaluateXPath(r,t),a=this.xpathEvaluator.toString(n);if(a){let l=t.outputDocument.createTextNode(a);i&&(l._disableOutputEscaping=!0),s.appendChild(l)}}xslText(e,t,s){let r=e.getAttribute("disable-output-escaping")==="yes",i="";for(let n of e.childNodes)(n.nodeType===3||n.nodeType===4)&&(i+=n.nodeValue||"");if(i){let n=t.outputDocument.createTextNode(i);r&&(n._disableOutputEscaping=!0),s.appendChild(n)}}xslElement(e,t,s){let r=this.processAttributeValueTemplate(e.getAttribute("name"),t),i=e.getAttribute("namespace"),n=e.getAttribute("use-attribute-sets"),a;if(i){let l=this.processAttributeValueTemplate(i,t);a=t.outputDocument.createElementNS(l,r)}else a=t.outputDocument.createElement(r);n&&this.applyAttributeSets(n,t,a),this.processChildren(e,t,a),s.appendChild(a)}xslAttribute(e,t,s){let r=this.processAttributeValueTemplate(e.getAttribute("name"),t),i=e.getAttribute("namespace"),n=t.outputDocument.createDocumentFragment();this.processChildren(e,t,n);let a="",l=h=>{if(h.nodeType===3||h.nodeType===4)a+=h.nodeValue||"";else if(h.childNodes)for(let p of h.childNodes)l(p)};if(l(n),s.nodeType===1)if(i){let h=this.processAttributeValueTemplate(i,t);s.setAttributeNS(h,r,a)}else s.setAttribute(r,a)}xslIf(e,t,s){let r=e.getAttribute("test"),i=this.evaluateXPath(r,t);this.xpathEvaluator.toBoolean(i)&&this.processChildren(e,t,s)}xslChoose(e,t,s){for(let r of e.childNodes)if(r.nodeType===1){if(this.isXsltElement(r,"when")){let i=r.getAttribute("test"),n=this.evaluateXPath(i,t);if(this.xpathEvaluator.toBoolean(n)){this.processChildren(r,t,s);return}}else if(this.isXsltElement(r,"otherwise")){this.processChildren(r,t,s);return}}}xslForEach(e,t,s){let r=e.getAttribute("select"),i=this.evaluateXPath(r,t);Array.isArray(i)||(i=i?[i]:[]);let n=[];for(let a of e.childNodes)a.nodeType===1&&this.isXsltElement(a,"sort")&&n.push({select:a.getAttribute("select")||".",order:a.getAttribute("order")||"ascending",dataType:a.getAttribute("data-type")||"text",caseOrder:a.getAttribute("case-order")||"upper-first",lang:a.getAttribute("lang")});n.length>0&&(i=this.sortNodes(i,n,t));for(let a=0;a<i.length;a++){let l=t.clone({currentNode:i[a],currentNodeList:i,position:a+1});this.processChildren(e,l,s)}}xslCopy(e,t,s){let r=t.currentNode,i=e.getAttribute("use-attribute-sets");switch(r.nodeType){case 1:{let n;r.namespaceURI?n=t.outputDocument.createElementNS(r.namespaceURI,r.nodeName):n=t.outputDocument.createElement(r.nodeName),i&&this.applyAttributeSets(i,t,n),this.processChildren(e,t,n),s.appendChild(n);break}case 2:s.nodeType===1&&s.setAttribute(r.name,r.value);break;case 3:case 4:{let n=t.outputDocument.createTextNode(r.nodeValue||"");s.appendChild(n);break}case 7:{let n=t.outputDocument.createProcessingInstruction(r.target,r.data);s.appendChild(n);break}case 8:{let n=t.outputDocument.createComment(r.nodeValue||"");s.appendChild(n);break}case 9:case 11:this.processChildren(e,t,s);break}}xslCopyOf(e,t,s){let r=e.getAttribute("select"),i=this.evaluateXPath(r,t);this.copyToOutput(i,t,s)}copyToOutput(e,t,s){if(Array.isArray(e)){for(let r of e)this.copyToOutput(r,t,s);return}if(e&&e.nodeType){let r=this.deepCloneNode(e,t.outputDocument);s.appendChild(r)}else if(typeof e=="string"||typeof e=="number"||typeof e=="boolean"){let r=t.outputDocument.createTextNode(String(e));s.appendChild(r)}}deepCloneNode(e,t){switch(e.nodeType){case 1:{let s;if(e.namespaceURI&&t.createElementNS?s=t.createElementNS(e.namespaceURI,e.nodeName):s=t.createElement(e.nodeName),e.attributes)for(let r of e.attributes)s.setAttribute(r.name,r.value);for(let r of e.childNodes)s.appendChild(this.deepCloneNode(r,t));return s}case 3:case 4:return t.createTextNode(e.nodeValue||"");case 7:return t.createProcessingInstruction(e.target,e.data);case 8:return t.createComment(e.nodeValue||"");case 11:{let s=t.createDocumentFragment();for(let r of e.childNodes)s.appendChild(this.deepCloneNode(r,t));return s}default:return t.createTextNode("")}}xslVariable(e,t,s){let r=e.getAttribute("name"),i=e.getAttribute("select"),n;if(i)n=this.evaluateXPath(i,t);else{let a=t.outputDocument.createDocumentFragment();this.processChildren(e,t,a),n=a}t.setVariable(r,n)}xslComment(e,t,s){let r=t.outputDocument.createDocumentFragment();this.processChildren(e,t,r);let i="",n=l=>{if(l.nodeType===3||l.nodeType===4)i+=l.nodeValue||"";else if(l.childNodes)for(let h of l.childNodes)n(h)};n(r);let a=t.outputDocument.createComment(i);s.appendChild(a)}xslProcessingInstruction(e,t,s){let r=this.processAttributeValueTemplate(e.getAttribute("name"),t),i=t.outputDocument.createDocumentFragment();this.processChildren(e,t,i);let n="",a=h=>{if(h.nodeType===3||h.nodeType===4)n+=h.nodeValue||"";else if(h.childNodes)for(let p of h.childNodes)a(p)};a(i);let l=t.outputDocument.createProcessingInstruction(r,n);s.appendChild(l)}xslNumber(e,t,s){let r=e.getAttribute("value"),i=e.getAttribute("format")||"1",n=e.getAttribute("level")||"single",a;r?a=Math.round(this.xpathEvaluator.toNumber(this.evaluateXPath(r,t))):a=this.countNumber(t.currentNode,n,e,t);let l=this.formatNumber(a,i),h=t.outputDocument.createTextNode(l);s.appendChild(h)}countNumber(e,t,s,r){let i=s.getAttribute("count"),n=s.getAttribute("from");if(t==="single"){let a=1,l=e.previousSibling;for(;l;)l.nodeType===1&&(!i||this.matchesPattern(l,i,r))&&a++,l=l.previousSibling;return a}return 1}formatNumber(e,t){return/^[0-9]+$/.test(t)?String(e).padStart(t.length,"0"):t==="a"?String.fromCharCode(96+(e-1)%26+1):t==="A"?String.fromCharCode(64+(e-1)%26+1):t==="i"?this.toRoman(e).toLowerCase():t==="I"?this.toRoman(e):String(e)}toRoman(e){let t=[["M",1e3],["CM",900],["D",500],["CD",400],["C",100],["XC",90],["L",50],["XL",40],["X",10],["IX",9],["V",5],["IV",4],["I",1]],s="";for(let[r,i]of t)for(;e>=i;)s+=r,e-=i;return s}xslMessage(e,t,s){let r=e.getAttribute("terminate")==="yes",i=t.outputDocument.createDocumentFragment();this.processChildren(e,t,i);let n="",a=l=>{if(l.nodeType===3||l.nodeType===4)n+=l.nodeValue||"";else if(l.childNodes)for(let h of l.childNodes)a(h)};if(a(i),console.log("XSLT Message:",n),r)throw new Error(`XSLT terminated: ${n}`)}applyAttributeSets(e,t,s){let r=e.split(/\s+/).filter(Boolean);for(let i of r){let n=this.attributeSets[i];if(n){n.useAttributeSets.length>0&&this.applyAttributeSets(n.useAttributeSets.join(" "),t,s);for(let a of n.node.childNodes)a.nodeType===1&&this.isXsltElement(a,"attribute")&&this.xslAttribute(a,t,s)}}}sortNodes(e,t,s){return[...e].sort((r,i)=>{for(let n of t){let a=s.clone({currentNode:r}),l=s.clone({currentNode:i}),h=this.evaluateXPath(n.select,a),p=this.evaluateXPath(n.select,l);h=this.xpathEvaluator.toString(h)||"",p=this.xpathEvaluator.toString(p)||"",n.dataType==="number"?(h=parseFloat(h)||0,p=parseFloat(p)||0):n.caseOrder==="lower-first"?(h=h.toLowerCase(),p=p.toLowerCase()):(h=h.toUpperCase(),p=p.toUpperCase());let d;if(typeof h=="number"?d=h-p:d=h.localeCompare(p,n.lang||void 0),n.order==="descending"&&(d=-d),d!==0)return d}return 0})}evaluateXPath(e,t){let s=T(e),r=new E(t.currentNode,t.position,t.currentNodeList.length,{...t.variables,...t.parameters},t.namespaces);return this.xpathEvaluator.evaluate(s,r)}isXsltNamespace(e){return e.namespaceURI===N||e.nodeName&&e.nodeName.startsWith("xsl:")}isXsltElement(e,t){if(e.nodeType!==1)return!1;let s=e.localName||e.nodeName;return e.namespaceURI===N&&s===t||e.nodeName===`xsl:${t}`}};var y=class{constructor(){this._engine=null,this._stylesheet=null,this._parameters=new Map}importStylesheet(e){if(!e)throw new TypeError("Failed to execute 'importStylesheet' on 'XSLTProcessor': 1 argument required, but only 0 present.");if(e.nodeType!==1&&e.nodeType!==9)throw new TypeError("Failed to execute 'importStylesheet' on 'XSLTProcessor': The node provided is not a Document or Element.");if(e.querySelector?e.querySelector("parsererror"):null)throw new Error("XSLT stylesheet contains parse errors");this._stylesheet=e,this._engine=new A;for(let[s,r]of this._parameters)this._engine.globalParameters[s]={value:r};this._engine.importStylesheet(e)}transformToFragment(e,t){if(!e)throw new TypeError("Failed to execute 'transformToFragment' on 'XSLTProcessor': 2 arguments required, but only 0 present.");if(!t)throw new TypeError("Failed to execute 'transformToFragment' on 'XSLTProcessor': 2 arguments required, but only 1 present.");if(!this._engine||!this._stylesheet)throw new Error("Failed to execute 'transformToFragment' on 'XSLTProcessor': No stylesheet has been imported.");if(e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)throw new TypeError("Failed to execute 'transformToFragment' on 'XSLTProcessor': The source is not a valid node type.");if(t.nodeType!==9)throw new TypeError("Failed to execute 'transformToFragment' on 'XSLTProcessor': The output is not a Document.");try{return this._engine.transform(e,t)}catch(s){return console.error("XSLT transformation error:",s),null}}transformToDocument(e){if(!e)throw new TypeError("Failed to execute 'transformToDocument' on 'XSLTProcessor': 1 argument required, but only 0 present.");if(!this._engine||!this._stylesheet)throw new Error("Failed to execute 'transformToDocument' on 'XSLTProcessor': No stylesheet has been imported.");if(e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)throw new TypeError("Failed to execute 'transformToDocument' on 'XSLTProcessor': The source is not a valid node type.");try{return this._engine.transformToDocument(e)}catch(t){return console.error("XSLT transformation error:",t),null}}setParameter(e,t,s){if(arguments.length<3)throw new TypeError(`Failed to execute 'setParameter' on 'XSLTProcessor': 3 arguments required, but only ${arguments.length} present.`);if(typeof t!="string"||t==="")throw new TypeError("Failed to execute 'setParameter' on 'XSLTProcessor': The localName argument must be a non-empty string.");let r=e?`{${e}}${t}`:t;this._parameters.set(r,s),this._engine&&(this._engine.globalParameters[r]={value:s})}getParameter(e,t){if(arguments.length<2)throw new TypeError(`Failed to execute 'getParameter' on 'XSLTProcessor': 2 arguments required, but only ${arguments.length} present.`);if(typeof t!="string")throw new TypeError("Failed to execute 'getParameter' on 'XSLTProcessor': The localName argument must be a string.");let s=e?`{${e}}${t}`:t;return this._parameters.has(s)?this._parameters.get(s):""}removeParameter(e,t){if(arguments.length<2)throw new TypeError(`Failed to execute 'removeParameter' on 'XSLTProcessor': 2 arguments required, but only ${arguments.length} present.`);if(typeof t!="string")throw new TypeError("Failed to execute 'removeParameter' on 'XSLTProcessor': The localName argument must be a string.");let s=e?`{${e}}${t}`:t;this._parameters.delete(s),this._engine&&delete this._engine.globalParameters[s]}clearParameters(){this._parameters.clear(),this._engine&&(this._engine.globalParameters={})}reset(){this._engine=null,this._stylesheet=null,this._parameters.clear()}};function _(){if(typeof globalThis.XSLTProcessor>"u")return!1;try{let m=new globalThis.XSLTProcessor,e=new DOMParser,t=e.parseFromString(`<?xml version="1.0"?>
|
|
1
|
+
var XsltProcessorLib=(()=>{var v=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var V=(m,e)=>{for(var t in e)v(m,t,{get:e[t],enumerable:!0})},$=(m,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of M(e))!B.call(m,r)&&r!==t&&v(m,r,{get:()=>e[r],enumerable:!(s=F(e,r))||s.enumerable});return m};var H=m=>$(v({},"__esModule",{value:!0}),m);var j={};V(j,{VERSION:()=>K,XPathContext:()=>E,XPathEvaluator:()=>g,XPathResultType:()=>R,XSLTProcessor:()=>y,XsltContext:()=>S,XsltEngine:()=>A,default:()=>I,evaluateXPath:()=>O,installGlobal:()=>k,isBrowser:()=>Q,isNativeXSLTSupported:()=>_,isNode:()=>W,parseXPath:()=>T,selectFirstXPath:()=>U,selectXPath:()=>D});var o={NUMBER:"NUMBER",LITERAL:"LITERAL",SLASH:"SLASH",DOUBLE_SLASH:"DOUBLE_SLASH",PIPE:"PIPE",PLUS:"PLUS",MINUS:"MINUS",STAR:"STAR",DIV:"DIV",MOD:"MOD",EQUALS:"EQUALS",NOT_EQUALS:"NOT_EQUALS",LT:"LT",LTE:"LTE",GT:"GT",GTE:"GTE",AND:"AND",OR:"OR",LPAREN:"LPAREN",RPAREN:"RPAREN",LBRACKET:"LBRACKET",RBRACKET:"RBRACKET",AXIS:"AXIS",AT:"AT",DOT:"DOT",DOUBLE_DOT:"DOUBLE_DOT",DOUBLE_COLON:"DOUBLE_COLON",NAME:"NAME",NCNAME:"NCNAME",PREFIX:"PREFIX",FUNCTION:"FUNCTION",NODE_TYPE:"NODE_TYPE",COMMA:"COMMA",DOLLAR:"DOLLAR",COLON:"COLON",EOF:"EOF"},Y=new Set(["ancestor","ancestor-or-self","attribute","child","descendant","descendant-or-self","following","following-sibling","namespace","parent","preceding","preceding-sibling","self"]),z=new Set(["comment","text","processing-instruction","node"]),G=new Set(["and","or","mod","div"]),f=class{constructor(e,t,s){this.type=e,this.value=t,this.position=s}toString(){return`Token(${this.type}, ${JSON.stringify(this.value)}, pos=${this.position})`}},q=new Set([o.AT,o.DOUBLE_COLON,o.LPAREN,o.LBRACKET,o.COMMA,o.SLASH,o.DOUBLE_SLASH,o.PIPE,o.PLUS,o.MINUS,o.STAR,o.DIV,o.MOD,o.EQUALS,o.NOT_EQUALS,o.LT,o.LTE,o.GT,o.GTE,o.AND,o.OR]),b=class{constructor(e){this.expression=e,this.position=0,this.tokens=[]}getLastToken(){return this.tokens.length>0?this.tokens[this.tokens.length-1]:null}isOperatorContext(){let e=this.getLastToken();return!(!e||q.has(e.type))}tokenize(){for(this.tokens=[],this.position=0;this.position<this.expression.length&&(this.skipWhitespace(),!(this.position>=this.expression.length));){let e=this.nextToken();e&&this.tokens.push(e)}return this.tokens.push(new f(o.EOF,null,this.position)),this.tokens}skipWhitespace(){for(;this.position<this.expression.length&&/\s/.test(this.expression[this.position]);)this.position++}peek(e=0){return this.expression[this.position+e]}consume(){return this.expression[this.position++]}nextToken(){let e=this.position,t=this.peek();if(t==='"'||t==="'")return this.readStringLiteral();if(/[0-9]/.test(t)||t==="."&&/[0-9]/.test(this.peek(1)))return this.readNumber();if(t==="/"&&this.peek(1)==="/")return this.position+=2,new f(o.DOUBLE_SLASH,"//",e);if(t==="."&&this.peek(1)===".")return this.position+=2,new f(o.DOUBLE_DOT,"..",e);if(t===":"&&this.peek(1)===":")return this.position+=2,new f(o.DOUBLE_COLON,"::",e);if(t==="!"&&this.peek(1)==="=")return this.position+=2,new f(o.NOT_EQUALS,"!=",e);if(t==="<"&&this.peek(1)==="=")return this.position+=2,new f(o.LTE,"<=",e);if(t===">"&&this.peek(1)==="=")return this.position+=2,new f(o.GTE,">=",e);let s={"/":o.SLASH,"|":o.PIPE,"+":o.PLUS,"-":o.MINUS,"*":o.STAR,"=":o.EQUALS,"<":o.LT,">":o.GT,"(":o.LPAREN,")":o.RPAREN,"[":o.LBRACKET,"]":o.RBRACKET,"@":o.AT,".":o.DOT,",":o.COMMA,$:o.DOLLAR,":":o.COLON};if(s[t])return this.position++,new f(s[t],t,e);if(this.isNameStartChar(t))return this.readName();throw new Error(`Unexpected character '${t}' at position ${this.position} in expression: ${this.expression}`)}readStringLiteral(){let e=this.position,t=this.consume(),s="";for(;this.position<this.expression.length&&this.peek()!==t;)s+=this.consume();if(this.position>=this.expression.length)throw new Error(`Unterminated string literal at position ${e}`);return this.consume(),new f(o.LITERAL,s,e)}readNumber(){let e=this.position,t="";for(;this.position<this.expression.length&&/[0-9]/.test(this.peek());)t+=this.consume();if(this.peek()==="."&&/[0-9]/.test(this.peek(1)))for(t+=this.consume();this.position<this.expression.length&&/[0-9]/.test(this.peek());)t+=this.consume();return new f(o.NUMBER,parseFloat(t),e)}readName(){let e=this.position,t="";for(;this.position<this.expression.length&&this.isNameChar(this.peek());)t+=this.consume();if(this.skipWhitespace(),Y.has(t)&&this.peek()===":"&&this.peek(1)===":")return new f(o.AXIS,t,e);let s=this.position;if(this.skipWhitespace(),this.peek()==="(")return z.has(t)?new f(o.NODE_TYPE,t,e):new f(o.FUNCTION,t,e);if(this.position=s,G.has(t)&&this.isOperatorContext()){let r={and:o.AND,or:o.OR,mod:o.MOD,div:o.DIV};return new f(r[t],t,e)}return new f(o.NAME,t,e)}isNameStartChar(e){if(!e)return!1;let t=e.charCodeAt(0);return e==="_"||t>=65&&t<=90||t>=97&&t<=122||t>=192}isNameChar(e){if(!e)return!1;let t=e.charCodeAt(0);return this.isNameStartChar(e)||e==="-"||e==="."||t>=48&&t<=57}};function x(m){return new b(m).tokenize()}var c={OR_EXPR:"OrExpr",AND_EXPR:"AndExpr",EQUALITY_EXPR:"EqualityExpr",RELATIONAL_EXPR:"RelationalExpr",ADDITIVE_EXPR:"AdditiveExpr",MULTIPLICATIVE_EXPR:"MultiplicativeExpr",UNARY_EXPR:"UnaryExpr",UNION_EXPR:"UnionExpr",PATH_EXPR:"PathExpr",LOCATION_PATH:"LocationPath",STEP:"Step",PREDICATE:"Predicate",VARIABLE_REF:"VariableRef",LITERAL:"Literal",NUMBER:"Number",FUNCTION_CALL:"FunctionCall",NAME_TEST:"NameTest",NODE_TYPE_TEST:"NodeTypeTest",PI_TEST:"ProcessingInstructionTest"},u=class{constructor(e,t={}){this.type=e,Object.assign(this,t)}},w=class{constructor(e){this.tokens=e,this.position=0}parse(){let e=this.parseExpr();if(!this.isAtEnd())throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().position}`);return e}parseExpr(){return this.parseOrExpr()}parseOrExpr(){let e=this.parseAndExpr();for(;this.match(o.OR);){let t=this.parseAndExpr();e=new u(c.OR_EXPR,{left:e,right:t})}return e}parseAndExpr(){let e=this.parseEqualityExpr();for(;this.match(o.AND);){let t=this.parseEqualityExpr();e=new u(c.AND_EXPR,{left:e,right:t})}return e}parseEqualityExpr(){let e=this.parseRelationalExpr();for(;;)if(this.match(o.EQUALS)){let t=this.parseRelationalExpr();e=new u(c.EQUALITY_EXPR,{operator:"=",left:e,right:t})}else if(this.match(o.NOT_EQUALS)){let t=this.parseRelationalExpr();e=new u(c.EQUALITY_EXPR,{operator:"!=",left:e,right:t})}else break;return e}parseRelationalExpr(){let e=this.parseAdditiveExpr();for(;;)if(this.match(o.LT)){let t=this.parseAdditiveExpr();e=new u(c.RELATIONAL_EXPR,{operator:"<",left:e,right:t})}else if(this.match(o.LTE)){let t=this.parseAdditiveExpr();e=new u(c.RELATIONAL_EXPR,{operator:"<=",left:e,right:t})}else if(this.match(o.GT)){let t=this.parseAdditiveExpr();e=new u(c.RELATIONAL_EXPR,{operator:">",left:e,right:t})}else if(this.match(o.GTE)){let t=this.parseAdditiveExpr();e=new u(c.RELATIONAL_EXPR,{operator:">=",left:e,right:t})}else break;return e}parseAdditiveExpr(){let e=this.parseMultiplicativeExpr();for(;;)if(this.match(o.PLUS)){let t=this.parseMultiplicativeExpr();e=new u(c.ADDITIVE_EXPR,{operator:"+",left:e,right:t})}else if(this.match(o.MINUS)){let t=this.parseMultiplicativeExpr();e=new u(c.ADDITIVE_EXPR,{operator:"-",left:e,right:t})}else break;return e}parseMultiplicativeExpr(){let e=this.parseUnaryExpr();for(;;)if(this.match(o.STAR)){let t=this.parseUnaryExpr();e=new u(c.MULTIPLICATIVE_EXPR,{operator:"*",left:e,right:t})}else if(this.match(o.DIV)){let t=this.parseUnaryExpr();e=new u(c.MULTIPLICATIVE_EXPR,{operator:"div",left:e,right:t})}else if(this.match(o.MOD)){let t=this.parseUnaryExpr();e=new u(c.MULTIPLICATIVE_EXPR,{operator:"mod",left:e,right:t})}else break;return e}parseUnaryExpr(){if(this.match(o.MINUS)){let e=this.parseUnaryExpr();return new u(c.UNARY_EXPR,{operator:"-",operand:e})}return this.parseUnionExpr()}parseUnionExpr(){let e=this.parsePathExpr();for(;this.match(o.PIPE);){let t=this.parsePathExpr();e=new u(c.UNION_EXPR,{left:e,right:t})}return e}parsePathExpr(){if(this.check(o.SLASH)||this.check(o.DOUBLE_SLASH))return this.parseLocationPath();if(this.isStepStart())return this.parseLocationPath();let e=this.parseFilterExpr();if(this.check(o.SLASH)||this.check(o.DOUBLE_SLASH)){let t=[];for(;this.check(o.SLASH)||this.check(o.DOUBLE_SLASH);){let s=this.match(o.DOUBLE_SLASH);s||this.advance(),s&&t.push(new u(c.STEP,{axis:"descendant-or-self",nodeTest:new u(c.NODE_TYPE_TEST,{nodeType:"node"}),predicates:[]})),t.push(this.parseStep())}return new u(c.PATH_EXPR,{filter:e,steps:t})}return e}parseLocationPath(){let e=!1,t=[];for(this.match(o.DOUBLE_SLASH)?(e=!0,t.push(new u(c.STEP,{axis:"descendant-or-self",nodeTest:new u(c.NODE_TYPE_TEST,{nodeType:"node"}),predicates:[]})),!this.isAtEnd()&&!this.check(o.EOF)&&t.push(this.parseStep())):this.match(o.SLASH)?(e=!0,this.isStepStart()&&t.push(this.parseStep())):t.push(this.parseStep());this.check(o.SLASH)||this.check(o.DOUBLE_SLASH);){let s=this.match(o.DOUBLE_SLASH);s||this.advance(),s&&t.push(new u(c.STEP,{axis:"descendant-or-self",nodeTest:new u(c.NODE_TYPE_TEST,{nodeType:"node"}),predicates:[]})),t.push(this.parseStep())}return new u(c.LOCATION_PATH,{absolute:e,steps:t})}parseStep(){if(this.match(o.DOT))return new u(c.STEP,{axis:"self",nodeTest:new u(c.NODE_TYPE_TEST,{nodeType:"node"}),predicates:[]});if(this.match(o.DOUBLE_DOT))return new u(c.STEP,{axis:"parent",nodeTest:new u(c.NODE_TYPE_TEST,{nodeType:"node"}),predicates:[]});let e="child";this.match(o.AT)?e="attribute":this.check(o.AXIS)&&(e=this.advance().value,this.expect(o.DOUBLE_COLON));let t=this.parseNodeTest(),s=[];for(;this.check(o.LBRACKET);)s.push(this.parsePredicate());return new u(c.STEP,{axis:e,nodeTest:t,predicates:s})}parseNodeTest(){if(this.check(o.NODE_TYPE)){let e=this.advance().value;if(this.expect(o.LPAREN),e==="processing-instruction"&&this.check(o.LITERAL)){let t=this.advance().value;return this.expect(o.RPAREN),new u(c.PI_TEST,{name:t})}return this.expect(o.RPAREN),new u(c.NODE_TYPE_TEST,{nodeType:e})}return this.parseNameTest()}parseNameTest(){if(this.match(o.STAR))return new u(c.NAME_TEST,{name:"*",prefix:null});if(!this.check(o.NAME))throw new Error(`Expected name at position ${this.peek().position}`);let e=this.advance().value;if(this.match(o.COLON)){if(this.match(o.STAR))return new u(c.NAME_TEST,{name:"*",prefix:e});if(this.check(o.NAME)){let t=this.advance().value;return new u(c.NAME_TEST,{name:t,prefix:e})}throw new Error(`Expected name or * after : at position ${this.peek().position}`)}return new u(c.NAME_TEST,{name:e,prefix:null})}parsePredicate(){this.expect(o.LBRACKET);let e=this.parseExpr();return this.expect(o.RBRACKET),new u(c.PREDICATE,{expr:e})}parseFilterExpr(){let e=this.parsePrimaryExpr();for(;this.check(o.LBRACKET);){let t=this.parsePredicate();e=new u(c.PATH_EXPR,{filter:e,predicates:[t]})}return e}parsePrimaryExpr(){if(this.match(o.DOLLAR)){if(!this.check(o.NAME))throw new Error(`Expected variable name at position ${this.peek().position}`);let e=this.advance().value,t=null;if(this.match(o.COLON)){if(t=e,!this.check(o.NAME))throw new Error(`Expected local name at position ${this.peek().position}`);let s=this.advance().value;return new u(c.VARIABLE_REF,{name:s,prefix:t})}return new u(c.VARIABLE_REF,{name:e,prefix:t})}if(this.match(o.LPAREN)){let e=this.parseExpr();return this.expect(o.RPAREN),e}if(this.check(o.LITERAL))return new u(c.LITERAL,{value:this.advance().value});if(this.check(o.NUMBER))return new u(c.NUMBER,{value:this.advance().value});if(this.check(o.FUNCTION))return this.parseFunctionCall();throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().position}`)}parseFunctionCall(){let e=this.advance().value;return this.parseFunctionCallArgs(e,null)}parseFunctionCallArgs(e,t){this.expect(o.LPAREN);let s=[];if(!this.check(o.RPAREN))for(s.push(this.parseExpr());this.match(o.COMMA);)s.push(this.parseExpr());return this.expect(o.RPAREN),new u(c.FUNCTION_CALL,{name:e,prefix:t,args:s})}isStepStart(){let e=this.peek().type;return e===o.NAME||e===o.STAR||e===o.AT||e===o.DOT||e===o.DOUBLE_DOT||e===o.AXIS||e===o.NODE_TYPE}peek(){return this.tokens[this.position]}advance(){return this.isAtEnd()?this.tokens[this.position]:this.tokens[this.position++]}check(e){return this.isAtEnd()?!1:this.peek().type===e}match(e){return this.check(e)?(this.advance(),!0):!1}expect(e){if(!this.check(e))throw new Error(`Expected ${e} but got ${this.peek().type} at position ${this.peek().position}`);return this.advance()}isAtEnd(){return this.peek().type===o.EOF}};function T(m){let e=x(m);return new w(e).parse()}var R={ANY_TYPE:0,NUMBER_TYPE:1,STRING_TYPE:2,BOOLEAN_TYPE:3,UNORDERED_NODE_ITERATOR_TYPE:4,ORDERED_NODE_ITERATOR_TYPE:5,UNORDERED_NODE_SNAPSHOT_TYPE:6,ORDERED_NODE_SNAPSHOT_TYPE:7,ANY_UNORDERED_NODE_TYPE:8,FIRST_ORDERED_NODE_TYPE:9},P={MAX_RECURSION_DEPTH:100,MAX_RESULT_SIZE:1e4,MAX_STRING_LENGTH:1e6},C=Object.freeze(["__proto__","constructor","prototype","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__"]),E=class m{constructor(e,t=1,s=1,r={},i={}){this.node=e,this.position=t,this.size=s,this.variables=r,this.namespaces=i}clone(e={}){return new m(e.node??this.node,e.position??this.position,e.size??this.size,e.variables??this.variables,e.namespaces??this.namespaces)}},g=class{constructor(e={}){this.functions=this.initCoreFunctions(),this.maxRecursionDepth=e.maxRecursionDepth??P.MAX_RECURSION_DEPTH,this.maxResultSize=e.maxResultSize??P.MAX_RESULT_SIZE,this.maxStringLength=e.maxStringLength??P.MAX_STRING_LENGTH,this.recursionDepth=0}evaluate(e,t){if(!e||typeof e!="object")throw new Error("Invalid AST: expected object");if(!e.type)throw new Error("Invalid AST: missing type property");if(this.recursionDepth++,this.recursionDepth>this.maxRecursionDepth)throw this.recursionDepth=0,new Error(`Maximum recursion depth exceeded (${this.maxRecursionDepth})`);try{return this.evaluateInternal(e,t)}finally{this.recursionDepth--}}evaluateInternal(e,t){switch(e.type){case c.OR_EXPR:return this.evalOrExpr(e,t);case c.AND_EXPR:return this.evalAndExpr(e,t);case c.EQUALITY_EXPR:return this.evalEqualityExpr(e,t);case c.RELATIONAL_EXPR:return this.evalRelationalExpr(e,t);case c.ADDITIVE_EXPR:return this.evalAdditiveExpr(e,t);case c.MULTIPLICATIVE_EXPR:return this.evalMultiplicativeExpr(e,t);case c.UNARY_EXPR:return this.evalUnaryExpr(e,t);case c.UNION_EXPR:return this.evalUnionExpr(e,t);case c.PATH_EXPR:return this.evalPathExpr(e,t);case c.LOCATION_PATH:return this.evalLocationPath(e,t);case c.VARIABLE_REF:return this.evalVariableRef(e,t);case c.LITERAL:return this.validateString(e.value);case c.NUMBER:return e.value;case c.FUNCTION_CALL:return this.evalFunctionCall(e,t);default:throw new Error(`Unknown AST node type: ${String(e.type)}`)}}validateString(e){if(typeof e=="string"&&e.length>this.maxStringLength)throw new Error(`String exceeds maximum length (${this.maxStringLength})`);return e}validateResultSize(e){if(Array.isArray(e)&&e.length>this.maxResultSize)throw new Error(`Result set exceeds maximum size (${this.maxResultSize})`);return e}evalOrExpr(e,t){return this.toBoolean(this.evaluate(e.left,t))||this.toBoolean(this.evaluate(e.right,t))}evalAndExpr(e,t){return this.toBoolean(this.evaluate(e.left,t))&&this.toBoolean(this.evaluate(e.right,t))}evalEqualityExpr(e,t){let s=this.evaluate(e.left,t),r=this.evaluate(e.right,t),i=this.compareValues(s,r,"=");return e.operator==="="?i:!i}evalRelationalExpr(e,t){let s=this.evaluate(e.left,t),r=this.evaluate(e.right,t);return this.compareValues(s,r,e.operator)}evalAdditiveExpr(e,t){let s=this.toNumber(this.evaluate(e.left,t)),r=this.toNumber(this.evaluate(e.right,t));return e.operator==="+"?s+r:s-r}evalMultiplicativeExpr(e,t){let s=this.toNumber(this.evaluate(e.left,t)),r=this.toNumber(this.evaluate(e.right,t));switch(e.operator){case"*":return s*r;case"div":return s/r;case"mod":return s%r;default:throw new Error(`Unknown multiplicative operator: ${e.operator}`)}}evalUnaryExpr(e,t){return-this.toNumber(this.evaluate(e.operand,t))}evalUnionExpr(e,t){let s=this.evaluate(e.left,t),r=this.evaluate(e.right,t),i=Array.isArray(s)?s:[s],n=Array.isArray(r)?r:[r],a=new Set,l=[];for(let h of[...i,...n])a.has(h)||(a.add(h),l.push(h));return this.validateResultSize(l),this.sortByDocumentOrder(l)}evalPathExpr(e,t){if(e.filter){let s=this.evaluate(e.filter,t);if(e.predicates)for(let r of e.predicates)s=this.filterByPredicate(s,r,t);if(e.steps)for(let r of e.steps)s=this.evalStepOnNodes(r,s,t);return s}return[]}evalLocationPath(e,t){let s;e.absolute?s=[t.node.ownerDocument||t.node]:s=[t.node];for(let r of e.steps)s=this.evalStepOnNodes(r,s,t),this.validateResultSize(s);return s}evalStepOnNodes(e,t,s){let r=Array.isArray(t)?t:[t],i=[];for(let a of r){let l=this.evalStep(e,s.clone({node:a}));i=i.concat(l),i.length>this.maxResultSize*2&&this.validateResultSize(i)}let n=[...new Set(i)];return this.validateResultSize(n),this.sortByDocumentOrder(n)}evalStep(e,t){let s=this.getAxisNodes(e.axis,t.node);s=s.filter(r=>this.matchNodeTest(e.nodeTest,r,t));for(let r of e.predicates)s=this.filterByPredicate(s,r,t);return s}getAxisNodes(e,t){switch(e){case"child":return Array.from(t.childNodes||[]);case"parent":return t.parentNode?[t.parentNode]:[];case"self":return[t];case"descendant":return this.getDescendants(t,!1);case"descendant-or-self":return this.getDescendants(t,!0);case"ancestor":return this.getAncestors(t,!1);case"ancestor-or-self":return this.getAncestors(t,!0);case"following-sibling":return this.getFollowingSiblings(t);case"preceding-sibling":return this.getPrecedingSiblings(t);case"following":return this.getFollowing(t);case"preceding":return this.getPreceding(t);case"attribute":return t.attributes?Array.from(t.attributes):[];case"namespace":return[];default:throw new Error(`Unknown axis: ${e}`)}}getDescendants(e,t){let s=t?[e]:[],r=Array.from(e.childNodes||[]).reverse();for(;r.length>0;){let i=r.pop();if(s.push(i),i.childNodes)for(let n=i.childNodes.length-1;n>=0;n--)r.push(i.childNodes[n])}return s}getAncestors(e,t){let s=t?[e]:[],r=e.parentNode;for(;r;)s.push(r),r=r.parentNode;return s}getFollowingSiblings(e){let t=[];if(!e)return t;let s=e.nextSibling;for(;s;)t.push(s),s=s.nextSibling;return t}getPrecedingSiblings(e){let t=[];if(!e)return t;let s=e.previousSibling;for(;s;)t.push(s),s=s.previousSibling;return t.reverse()}getFollowing(e){let t=[],s=e;for(;s;)s.nextSibling?(s=s.nextSibling,t.push(s),t.push(...this.getDescendants(s,!1))):s=s.parentNode;return t}getPreceding(e){let t=[],s=e;for(;s;)if(s.previousSibling){s=s.previousSibling;let r=this.getDescendants(s,!1);t.unshift(...r.reverse()),t.unshift(s)}else s=s.parentNode,s&&s.nodeType;return t}matchNodeTest(e,t,s){switch(e.type){case c.NAME_TEST:return this.matchNameTest(e,t,s);case c.NODE_TYPE_TEST:return this.matchNodeTypeTest(e.nodeType,t);case c.PI_TEST:return t.nodeType===7&&t.nodeName===e.name;default:return!1}}matchNameTest(e,t,s){if(t.nodeType!==1&&t.nodeType!==2)return!1;let r=e.name,i=e.prefix;if(r==="*"&&!i)return!0;let n=t.localName||t.nodeName,a=t.namespaceURI||null;if(r==="*"&&i){let h=s.namespaces[i];return a===h}if(!i){let h=t.ownerDocument;return h&&h.contentType==="text/html"&&t.nodeType===1?n.toLowerCase()===r.toLowerCase():n===r}let l=s.namespaces[i];return n===r&&a===l}matchNodeTypeTest(e,t){switch(e){case"node":return!0;case"text":return t.nodeType===3;case"comment":return t.nodeType===8;case"processing-instruction":return t.nodeType===7;default:return!1}}filterByPredicate(e,t,s){let r=[],i=Array.isArray(e)?e:[e],n=i.length;for(let a=0;a<i.length;a++){let l=i[a],h=s.clone({node:l,position:a+1,size:n}),p=this.evaluate(t.expr,h);typeof p=="number"?p===a+1&&r.push(l):this.toBoolean(p)&&r.push(l)}return r}evalVariableRef(e,t){let s=e.prefix?`${e.prefix}:${e.name}`:e.name;if(C.includes(s)||C.includes(e.name))throw new Error(`Forbidden variable name: $${s}`);if(!Object.prototype.hasOwnProperty.call(t.variables,s))throw new Error(`Undefined variable: $${s}`);return t.variables[s]}evalFunctionCall(e,t){let s=e.prefix?`${e.prefix}:${e.name}`:e.name,r=this.functions[s];if(!r)throw new Error(`Unknown function: ${s}`);return r.call(this,e.args,t)}toBoolean(e){return typeof e=="boolean"?e:typeof e=="number"?e!==0&&!isNaN(e):typeof e=="string"||Array.isArray(e)?e.length>0:e&&e.nodeType?!0:!!e}toNumber(e){if(typeof e=="number")return e;if(typeof e=="boolean")return e?1:0;if(typeof e=="string"){let t=e.trim();return t===""?NaN:Number(t)}return Array.isArray(e)?this.toNumber(this.toString(e)):e&&e.nodeType?this.toNumber(this.getStringValue(e)):NaN}toString(e){return typeof e=="string"?e:typeof e=="number"?isNaN(e)?"NaN":e===1/0?"Infinity":e===-1/0?"-Infinity":e===0?"0":String(e):typeof e=="boolean"?e?"true":"false":Array.isArray(e)?e.length===0?"":this.getStringValue(e[0]):e&&e.nodeType?this.getStringValue(e):String(e)}getStringValue(e){if(!e)return"";switch(e.nodeType){case 1:case 9:case 11:{let t="",s=r=>{if(r.nodeType===3)t+=r.nodeValue||"";else if(r.childNodes)for(let i of r.childNodes)s(i)};return s(e),t}case 2:case 3:case 4:case 7:case 8:return e.nodeValue||"";default:return""}}compareValues(e,t,s){let r=Array.isArray(e),i=Array.isArray(t);if(r&&i){for(let n of e)for(let a of t)if(this.comparePrimitive(this.getStringValue(n),this.getStringValue(a),s))return!0;return!1}if(r){for(let n of e)if(this.comparePrimitive(this.getStringValue(n),t,s))return!0;return!1}if(i){for(let n of t)if(this.comparePrimitive(e,this.getStringValue(n),s))return!0;return!1}return this.comparePrimitive(e,t,s)}comparePrimitive(e,t,s){if(s==="="||s==="!="){if(typeof e=="boolean"||typeof t=="boolean"){let a=this.toBoolean(e)===this.toBoolean(t);return s==="="?a:!a}if(typeof e=="number"||typeof t=="number"){let a=this.toNumber(e)===this.toNumber(t);return s==="="?a:!a}let n=this.toString(e)===this.toString(t);return s==="="?n:!n}let r=this.toNumber(e),i=this.toNumber(t);switch(s){case"<":return r<i;case"<=":return r<=i;case">":return r>i;case">=":return r>=i;default:throw new Error(`Unknown comparison operator: ${s}`)}}sortByDocumentOrder(e){return e.length<=1?e:e.sort((t,s)=>{if(t===s)return 0;let r=t.compareDocumentPosition?t.compareDocumentPosition(s):this.compareDocumentPositionFallback(t,s);return r&4?-1:r&2?1:0})}compareDocumentPositionFallback(e,t){let s=n=>{let a=[],l=n;for(;l;){if(l.parentNode){let h=Array.from(l.parentNode.childNodes);a.unshift(h.indexOf(l))}l=l.parentNode}return a},r=s(e),i=s(t);for(let n=0;n<Math.min(r.length,i.length);n++){if(r[n]<i[n])return 4;if(r[n]>i[n])return 2}return r.length<i.length?4:2}initCoreFunctions(){return{last:(e,t)=>t.size,position:(e,t)=>t.position,count:(e,t)=>{let s=this.evaluate(e[0],t);return Array.isArray(s)?s.length:1},id:(e,t)=>{let s=this.toString(this.evaluate(e[0],t)),r=t.node.ownerDocument||t.node,i=s.split(/\s+/).filter(a=>a),n=[];for(let a of i){let l=r.getElementById(a);l&&n.push(l)}return n},"local-name":(e,t)=>{let s;if(e.length===0)s=t.node;else{let r=this.evaluate(e[0],t);s=Array.isArray(r)?r[0]:r}return s&&(s.localName||s.nodeName)||""},"namespace-uri":(e,t)=>{let s;if(e.length===0)s=t.node;else{let r=this.evaluate(e[0],t);s=Array.isArray(r)?r[0]:r}return s&&s.namespaceURI||""},name:(e,t)=>{let s;if(e.length===0)s=t.node;else{let r=this.evaluate(e[0],t);s=Array.isArray(r)?r[0]:r}return s&&s.nodeName||""},string:(e,t)=>e.length===0?this.toString([t.node]):this.toString(this.evaluate(e[0],t)),concat:(e,t)=>e.map(s=>this.toString(this.evaluate(s,t))).join(""),"starts-with":(e,t)=>{let s=this.toString(this.evaluate(e[0],t)),r=this.toString(this.evaluate(e[1],t));return s.startsWith(r)},contains:(e,t)=>{let s=this.toString(this.evaluate(e[0],t)),r=this.toString(this.evaluate(e[1],t));return s.includes(r)},"substring-before":(e,t)=>{let s=this.toString(this.evaluate(e[0],t)),r=this.toString(this.evaluate(e[1],t)),i=s.indexOf(r);return i===-1?"":s.substring(0,i)},"substring-after":(e,t)=>{let s=this.toString(this.evaluate(e[0],t)),r=this.toString(this.evaluate(e[1],t)),i=s.indexOf(r);return i===-1?"":s.substring(i+r.length)},substring:(e,t)=>{let s=this.toString(this.evaluate(e[0],t)),r=Math.round(this.toNumber(this.evaluate(e[1],t))),i;return e.length>2&&(i=Math.round(this.toNumber(this.evaluate(e[2],t)))),r=r-1,isNaN(r)?"":(r<0&&(i!==void 0&&(i=i+r),r=0),i!==void 0?isNaN(i)||i<=0?"":s.substring(r,r+i):s.substring(r))},"string-length":(e,t)=>(e.length===0?this.toString([t.node]):this.toString(this.evaluate(e[0],t))).length,"normalize-space":(e,t)=>(e.length===0?this.toString([t.node]):this.toString(this.evaluate(e[0],t))).trim().replace(/\s+/g," "),translate:(e,t)=>{let s=this.toString(this.evaluate(e[0],t)),r=this.toString(this.evaluate(e[1],t)),i=this.toString(this.evaluate(e[2],t)),n="";for(let a of s){let l=r.indexOf(a);l===-1?n+=a:l<i.length&&(n+=i[l])}return n},boolean:(e,t)=>this.toBoolean(this.evaluate(e[0],t)),not:(e,t)=>!this.toBoolean(this.evaluate(e[0],t)),true:()=>!0,false:()=>!1,lang:(e,t)=>{let s=this.toString(this.evaluate(e[0],t)).toLowerCase(),r=t.node;for(;r&&r.nodeType===1;){let i=r.getAttribute("xml:lang")||r.getAttribute("lang");if(i){let n=i.toLowerCase();return n===s||n.startsWith(s+"-")}r=r.parentNode}return!1},number:(e,t)=>e.length===0?this.toNumber([t.node]):this.toNumber(this.evaluate(e[0],t)),sum:(e,t)=>{let s=this.evaluate(e[0],t);return Array.isArray(s)?s.reduce((r,i)=>r+this.toNumber(this.getStringValue(i)),0):NaN},floor:(e,t)=>Math.floor(this.toNumber(this.evaluate(e[0],t))),ceiling:(e,t)=>Math.ceil(this.toNumber(this.evaluate(e[0],t))),round:(e,t)=>{let s=this.toNumber(this.evaluate(e[0],t));return isNaN(s)?NaN:s===-.5?-0:Math.round(s)}}}};var N="http://www.w3.org/1999/XSL/Transform",S=class m{constructor(e={}){this.currentNode=e.currentNode,this.currentNodeList=e.currentNodeList||[],this.position=e.position||1,this.variables={...e.variables},this.parameters={...e.parameters},this.outputDocument=e.outputDocument,this.stylesheet=e.stylesheet,this.namespaces={...e.namespaces},this.templates=e.templates||[],this.keys=e.keys||{},this.decimalFormats=e.decimalFormats||{},this.outputMethod=e.outputMethod||"xml",this.xpathEvaluator=e.xpathEvaluator||new g}clone(e={}){return new m({currentNode:e.currentNode??this.currentNode,currentNodeList:e.currentNodeList??this.currentNodeList,position:e.position??this.position,variables:e.variables?{...this.variables,...e.variables}:{...this.variables},parameters:e.parameters?{...this.parameters,...e.parameters}:{...this.parameters},outputDocument:this.outputDocument,stylesheet:this.stylesheet,namespaces:e.namespaces?{...this.namespaces,...e.namespaces}:{...this.namespaces},templates:this.templates,keys:this.keys,decimalFormats:this.decimalFormats,outputMethod:this.outputMethod,xpathEvaluator:this.xpathEvaluator})}getVariable(e){if(e in this.variables)return this.variables[e];if(e in this.parameters)return this.parameters[e];throw new Error(`Undefined variable: $${e}`)}setVariable(e,t){this.variables[e]=t}},A=class{constructor(e={}){this.xpathEvaluator=new g,this.templates=[],this.keys={},this.globalVariables={},this.globalParameters={},this.outputSettings={method:"xml",encoding:"UTF-8",indent:"no",omitXmlDeclaration:"no",doctypePublic:null,doctypeSystem:null,mediaType:null,cdataSectionElements:[]},this.namespaces={},this.decimalFormats={},this.stylesheetDoc=null,this.attributeSets={},this.namespaceAliases={},this.stripSpace=[],this.preserveSpace=[],this.stylesheetLoader=e.stylesheetLoader||null,this.currentImportPrecedence=0,this.processedStylesheets=new Set,this.baseUri=e.baseUri||""}setStylesheetLoader(e){this.stylesheetLoader=e}resolveUri(e,t){if(!t||e.startsWith("http://")||e.startsWith("https://")||e.startsWith("/"))return e;let s=t.lastIndexOf("/");return(s>=0?t.substring(0,s+1):"")+e}loadStylesheet(e,t){if(!this.stylesheetLoader)throw new Error(`Cannot load stylesheet "${e}": no stylesheetLoader configured. Use engine.setStylesheetLoader(fn) to provide a loader function.`);let s=this.resolveUri(e,t);return{document:this.stylesheetLoader(s,t),uri:s}}parseXmlString(e){if(typeof DOMParser<"u"){let s=new DOMParser().parseFromString(e,"application/xml"),r=s.querySelector("parsererror");if(r)throw new Error(`XML parse error: ${r.textContent}`);return s}throw new Error("XML parsing not available in this environment")}importStylesheet(e,t){let s=this.stylesheetDoc===null;s&&(this.stylesheetDoc=e.ownerDocument||e,t&&(this.baseUri=t,this.processedStylesheets.add(t)));let r=e.documentElement||e;if(!this.isXsltElement(r,"stylesheet")&&!this.isXsltElement(r,"transform")){if(r.getAttribute&&r.getAttribute("xsl:version")){this.processLiteralResultStylesheet(r);return}throw new Error("Invalid XSLT stylesheet: root element must be xsl:stylesheet or xsl:transform")}this.collectNamespaces(r);let i=[],n=[];for(let a of r.childNodes)a.nodeType===1&&(this.isXsltElement(a,"import")?i.push(a):n.push(a));for(let a of i)this.processImport(a,t||this.baseUri);for(let a of n)this.isXsltElement(a,"template")?this.registerTemplate(a):this.isXsltElement(a,"output")?this.processOutput(a):this.isXsltElement(a,"variable")?this.processGlobalVariable(a):this.isXsltElement(a,"param")?this.processGlobalParam(a):this.isXsltElement(a,"key")?this.processKey(a):this.isXsltElement(a,"decimal-format")?this.processDecimalFormat(a):this.isXsltElement(a,"namespace-alias")?this.processNamespaceAlias(a):this.isXsltElement(a,"attribute-set")?this.processAttributeSet(a):this.isXsltElement(a,"strip-space")?this.processStripSpace(a):this.isXsltElement(a,"preserve-space")?this.processPreserveSpace(a):this.isXsltElement(a,"include")&&this.processInclude(a,t||this.baseUri);s&&this.currentImportPrecedence++}processInclude(e,t){let s=e.getAttribute("href");if(!s)throw new Error("xsl:include requires an href attribute");let r=this.resolveUri(s,t);if(this.processedStylesheets.has(r))throw new Error(`Circular stylesheet reference detected: ${r}`);this.processedStylesheets.add(r);try{let{document:i}=this.loadStylesheet(s,t),n=i;typeof i=="string"&&(n=this.parseXmlString(i));let a=this.currentImportPrecedence;this.processIncludedStylesheet(n,r),this.currentImportPrecedence=a}catch(i){throw new Error(`Failed to include stylesheet "${s}": ${i.message}`)}}processImport(e,t){let s=e.getAttribute("href");if(!s)throw new Error("xsl:import requires an href attribute");let r=this.resolveUri(s,t);if(this.processedStylesheets.has(r))throw new Error(`Circular stylesheet reference detected: ${r}`);this.processedStylesheets.add(r);try{let{document:i}=this.loadStylesheet(s,t),n=i;typeof i=="string"&&(n=this.parseXmlString(i)),this.processIncludedStylesheet(n,r),this.currentImportPrecedence++}catch(i){throw new Error(`Failed to import stylesheet "${s}": ${i.message}`)}}processIncludedStylesheet(e,t){let s=e.documentElement||e;if(!this.isXsltElement(s,"stylesheet")&&!this.isXsltElement(s,"transform"))throw new Error("Included/imported document is not a valid XSLT stylesheet");this.collectNamespaces(s);let r=[],i=[];for(let n of s.childNodes)n.nodeType===1&&(this.isXsltElement(n,"import")?r.push(n):i.push(n));for(let n of r)this.processImport(n,t);for(let n of i)this.isXsltElement(n,"template")?this.registerTemplate(n):this.isXsltElement(n,"output")?this.processOutput(n):this.isXsltElement(n,"variable")?this.processGlobalVariable(n):this.isXsltElement(n,"param")?this.processGlobalParam(n):this.isXsltElement(n,"key")?this.processKey(n):this.isXsltElement(n,"decimal-format")?this.processDecimalFormat(n):this.isXsltElement(n,"namespace-alias")?this.processNamespaceAlias(n):this.isXsltElement(n,"attribute-set")?this.processAttributeSet(n):this.isXsltElement(n,"strip-space")?this.processStripSpace(n):this.isXsltElement(n,"preserve-space")?this.processPreserveSpace(n):this.isXsltElement(n,"include")&&this.processInclude(n,t)}processLiteralResultStylesheet(e){this.templates.push({match:"/",name:null,mode:null,priority:.5,node:e})}collectNamespaces(e){if(e.attributes)for(let t of e.attributes)if(t.name.startsWith("xmlns:")){let s=t.name.substring(6);t.value!==N&&(this.namespaces[s]=t.value)}else t.name==="xmlns"&&t.value!==N&&(this.namespaces[""]=t.value)}registerTemplate(e){let t=e.getAttribute("match"),s=e.getAttribute("name"),r=e.getAttribute("mode")||null,i=e.getAttribute("priority"),n=i?parseFloat(i):this.calculatePriority(t);this.templates.push({match:t,name:s,mode:r,priority:n,importPrecedence:this.currentImportPrecedence,node:e})}calculatePriority(e){return e?e==="*"||e==="node()"||e==="text()"||e==="comment()"||e==="processing-instruction()"?-.5:e.includes(":*")?-.25:/^[a-zA-Z_][\w.-]*$/.test(e)?0:.5:.5}processOutput(e){let t=e.getAttribute("method");t&&(this.outputSettings.method=t);let s=e.getAttribute("encoding");s&&(this.outputSettings.encoding=s);let r=e.getAttribute("indent");r&&(this.outputSettings.indent=r);let i=e.getAttribute("omit-xml-declaration");i&&(this.outputSettings.omitXmlDeclaration=i);let n=e.getAttribute("doctype-public");n&&(this.outputSettings.doctypePublic=n);let a=e.getAttribute("doctype-system");a&&(this.outputSettings.doctypeSystem=a);let l=e.getAttribute("media-type");l&&(this.outputSettings.mediaType=l);let h=e.getAttribute("cdata-section-elements");h&&(this.outputSettings.cdataSectionElements=h.split(/\s+/).filter(Boolean))}processGlobalVariable(e){let t=e.getAttribute("name"),s=e.getAttribute("select");this.globalVariables[t]={node:e,select:s}}processGlobalParam(e){let t=e.getAttribute("name"),s=e.getAttribute("select");this.globalParameters[t]={node:e,select:s}}processKey(e){let t=e.getAttribute("name"),s=e.getAttribute("match"),r=e.getAttribute("use");this.keys[t]={match:s,use:r}}processDecimalFormat(e){let t=e.getAttribute("name")||"";this.decimalFormats[t]={decimalSeparator:e.getAttribute("decimal-separator")||".",groupingSeparator:e.getAttribute("grouping-separator")||",",percent:e.getAttribute("percent")||"%",perMille:e.getAttribute("per-mille")||"\u2030",zeroDigit:e.getAttribute("zero-digit")||"0",digit:e.getAttribute("digit")||"#",patternSeparator:e.getAttribute("pattern-separator")||";",infinity:e.getAttribute("infinity")||"Infinity",nan:e.getAttribute("NaN")||"NaN",minusSign:e.getAttribute("minus-sign")||"-"}}processNamespaceAlias(e){let t=e.getAttribute("stylesheet-prefix"),s=e.getAttribute("result-prefix");this.namespaceAliases[t]=s}processAttributeSet(e){let t=e.getAttribute("name"),s=e.getAttribute("use-attribute-sets");this.attributeSets[t]={node:e,useAttributeSets:s?s.split(/\s+/).filter(Boolean):[]}}processStripSpace(e){let t=e.getAttribute("elements");t&&this.stripSpace.push(...t.split(/\s+/).filter(Boolean))}processPreserveSpace(e){let t=e.getAttribute("elements");t&&this.preserveSpace.push(...t.split(/\s+/).filter(Boolean))}transform(e,t){let s=t||(typeof document<"u"?document:null);if(!s)throw new Error("No output document available");let r=new S({currentNode:e,currentNodeList:[e],position:1,outputDocument:s,stylesheet:this.stylesheetDoc,namespaces:{...this.namespaces},templates:this.templates,keys:this.keys,decimalFormats:this.decimalFormats,outputMethod:this.outputSettings.method,xpathEvaluator:this.xpathEvaluator});for(let[n,a]of Object.entries(this.globalParameters))n in r.parameters||(r.parameters[n]=this.evaluateVariable(a,r));for(let[n,a]of Object.entries(this.globalVariables))r.variables[n]=this.evaluateVariable(a,r);let i=s.createDocumentFragment();return this.applyTemplates([e.documentElement||e],null,r,i),i}transformToDocument(e){let t=this.createDocument(),s=this.transform(e,t);for(;s.firstChild;)t.appendChild(s.firstChild);return t}createDocument(){if(typeof document<"u")return document.implementation.createDocument(null,null,null);throw new Error("Document creation not available in this environment")}evaluateVariable(e,t){if(e.select)return this.evaluateXPath(e.select,t);let s=t.outputDocument.createDocumentFragment();return this.processChildren(e.node,t,s),s}applyTemplates(e,t,s,r){let i=Array.isArray(e)?e:[e];for(let n=0;n<i.length;n++){let a=i[n],l=this.findMatchingTemplate(a,t,s);if(l){let h=s.clone({currentNode:a,currentNodeList:i,position:n+1});this.processTemplate(l.node,h,r)}else this.applyBuiltinTemplate(a,t,s,r)}}findMatchingTemplate(e,t,s){let r=null,i=-1/0,n=-1/0;for(let a of this.templates)if(a.mode===t&&a.match&&this.matchesPattern(e,a.match,s)){let l=a.priority,h=a.importPrecedence||0;(h>n||h===n&&l>i)&&(r=a,i=l,n=h)}return r}matchesPattern(e,t,s){let r=this.splitUnionPattern(t);for(let i of r)if(this.matchesSinglePattern(e,i.trim(),s))return!0;return!1}splitUnionPattern(e){let t=[],s="",r=0,i=!1,n="";for(let a=0;a<e.length;a++){let l=e[a];i?(s+=l,l===n&&(i=!1)):l==='"'||l==="'"?(i=!0,n=l,s+=l):l==="["?(r++,s+=l):l==="]"?(r--,s+=l):l==="|"&&r===0?(t.push(s),s=""):s+=l}return s&&t.push(s),t}matchesSinglePattern(e,t,s){var r;try{if(t==="/")return e.nodeType===9||e===((r=e.ownerDocument)==null?void 0:r.documentElement);let i=T(t);if(t.startsWith("/")){let h=e.ownerDocument||e,p=new E(h,1,1,{...s.variables,...s.parameters},s.namespaces),d=this.xpathEvaluator.evaluate(i,p);return(Array.isArray(d)?d:[d]).includes(e)}if(e.parentNode){let h=new E(e.parentNode,1,1,{...s.variables,...s.parameters},s.namespaces),p=this.xpathEvaluator.evaluate(i,h);return(Array.isArray(p)?p:[p]).includes(e)}let n=new E(e,1,1,{...s.variables,...s.parameters},s.namespaces),a=this.xpathEvaluator.evaluate(i,n);return(Array.isArray(a)?a:[a]).includes(e)}catch{return!1}}applyBuiltinTemplate(e,t,s,r){switch(e.nodeType){case 1:case 9:case 11:this.applyTemplates(Array.from(e.childNodes),t,s,r);break;case 3:case 4:{let i=s.outputDocument.createTextNode(e.nodeValue||"");r.appendChild(i);break}case 2:{let i=s.outputDocument.createTextNode(e.nodeValue||"");r.appendChild(i);break}}}processTemplate(e,t,s){let r=t.clone();for(let i of e.childNodes)if(i.nodeType===1&&this.isXsltElement(i,"param")){let n=i.getAttribute("name");n in r.parameters||(r.parameters[n]=this.evaluateVariable({node:i,select:i.getAttribute("select")},r))}this.processChildren(e,r,s)}processChildren(e,t,s){for(let r of e.childNodes)this.processNode(r,t,s)}processNode(e,t,s){switch(e.nodeType){case 1:this.processElement(e,t,s);break;case 3:case 4:{let r=e.nodeValue;if(r&&(r.trim()||this.shouldPreserveSpace(e))){let i=t.outputDocument.createTextNode(r);s.appendChild(i)}break}}}shouldPreserveSpace(e){let t=e.parentNode;for(;t&&t.nodeType===1;){let s=t.getAttribute("xml:space");if(s==="preserve")return!0;if(s==="default")return!1;t=t.parentNode}return!1}processElement(e,t,s){this.isXsltNamespace(e)?this.processXsltElement(e,t,s):this.processLiteralResultElement(e,t,s)}processXsltElement(e,t,s){let r=e.localName||e.nodeName.replace(/^xsl:/,"");switch(r){case"apply-templates":this.xslApplyTemplates(e,t,s);break;case"call-template":this.xslCallTemplate(e,t,s);break;case"value-of":this.xslValueOf(e,t,s);break;case"text":this.xslText(e,t,s);break;case"element":this.xslElement(e,t,s);break;case"attribute":this.xslAttribute(e,t,s);break;case"if":this.xslIf(e,t,s);break;case"choose":this.xslChoose(e,t,s);break;case"for-each":this.xslForEach(e,t,s);break;case"copy":this.xslCopy(e,t,s);break;case"copy-of":this.xslCopyOf(e,t,s);break;case"variable":this.xslVariable(e,t,s);break;case"param":break;case"comment":this.xslComment(e,t,s);break;case"processing-instruction":this.xslProcessingInstruction(e,t,s);break;case"number":this.xslNumber(e,t,s);break;case"sort":break;case"with-param":break;case"message":this.xslMessage(e,t,s);break;case"fallback":break;default:console.warn(`Unknown XSLT element: ${r}`)}}processLiteralResultElement(e,t,s){let r,i=e.namespaceURI,n=e.nodeName,a=i;if(i){for(let[l,h]of Object.entries(this.namespaceAliases))if(this.namespaces[l]===i){a=this.namespaces[h]||h;break}}if(a&&t.outputDocument.createElementNS?r=t.outputDocument.createElementNS(a,n):r=t.outputDocument.createElement(n),e.attributes)for(let l of e.attributes){if(l.namespaceURI===N||l.name.startsWith("xmlns"))continue;let h=this.processAttributeValueTemplate(l.value,t);r.setAttribute(l.name,h)}this.processChildren(e,t,r),s.appendChild(r)}processAttributeValueTemplate(e,t){if(!e.includes("{"))return e;let s="",r=0;for(;r<e.length;)if(e[r]==="{")if(e[r+1]==="{")s+="{",r+=2;else{let i=1,n=r+1;for(;n<e.length&&i>0;)e[n]==="{"?i++:e[n]==="}"&&i--,n++;let a=e.substring(r+1,n-1),l=this.evaluateXPath(a,t);s+=this.xpathEvaluator.toString(l),r=n}else if(e[r]==="}")if(e[r+1]==="}")s+="}",r+=2;else throw new Error("Unmatched } in attribute value template");else s+=e[r],r++;return s}xslApplyTemplates(e,t,s){let r=e.getAttribute("select")||"node()",i=e.getAttribute("mode")||null,n=this.evaluateXPath(r,t);Array.isArray(n)||(n=n?[n]:[]);let a=[];for(let p of e.childNodes)p.nodeType===1&&this.isXsltElement(p,"sort")&&a.push({select:p.getAttribute("select")||".",order:p.getAttribute("order")||"ascending",dataType:p.getAttribute("data-type")||"text",caseOrder:p.getAttribute("case-order")||"upper-first",lang:p.getAttribute("lang")});a.length>0&&(n=this.sortNodes(n,a,t));let l={};for(let p of e.childNodes)if(p.nodeType===1&&this.isXsltElement(p,"with-param")){let d=p.getAttribute("name"),L=p.getAttribute("select");if(L)l[d]=this.evaluateXPath(L,t);else{let X=t.outputDocument.createDocumentFragment();this.processChildren(p,t,X),l[d]=X}}let h=t.clone({parameters:{...t.parameters,...l}});this.applyTemplates(n,i,h,s)}xslCallTemplate(e,t,s){let r=e.getAttribute("name"),i=this.templates.find(l=>l.name===r);if(!i)throw new Error(`Template not found: ${r}`);let n={};for(let l of e.childNodes)if(l.nodeType===1&&this.isXsltElement(l,"with-param")){let h=l.getAttribute("name"),p=l.getAttribute("select");if(p)n[h]=this.evaluateXPath(p,t);else{let d=t.outputDocument.createDocumentFragment();this.processChildren(l,t,d),n[h]=d}}let a=t.clone({parameters:{...t.parameters,...n}});this.processTemplate(i.node,a,s)}xslValueOf(e,t,s){let r=e.getAttribute("select"),i=e.getAttribute("disable-output-escaping")==="yes",n=this.evaluateXPath(r,t),a=this.xpathEvaluator.toString(n);if(a){let l=t.outputDocument.createTextNode(a);i&&(l._disableOutputEscaping=!0),s.appendChild(l)}}xslText(e,t,s){let r=e.getAttribute("disable-output-escaping")==="yes",i="";for(let n of e.childNodes)(n.nodeType===3||n.nodeType===4)&&(i+=n.nodeValue||"");if(i){let n=t.outputDocument.createTextNode(i);r&&(n._disableOutputEscaping=!0),s.appendChild(n)}}xslElement(e,t,s){let r=this.processAttributeValueTemplate(e.getAttribute("name"),t),i=e.getAttribute("namespace"),n=e.getAttribute("use-attribute-sets"),a;if(i){let l=this.processAttributeValueTemplate(i,t);a=t.outputDocument.createElementNS(l,r)}else a=t.outputDocument.createElement(r);n&&this.applyAttributeSets(n,t,a),this.processChildren(e,t,a),s.appendChild(a)}xslAttribute(e,t,s){let r=this.processAttributeValueTemplate(e.getAttribute("name"),t),i=e.getAttribute("namespace"),n=t.outputDocument.createDocumentFragment();this.processChildren(e,t,n);let a="",l=h=>{if(h.nodeType===3||h.nodeType===4)a+=h.nodeValue||"";else if(h.childNodes)for(let p of h.childNodes)l(p)};if(l(n),s.nodeType===1)if(i){let h=this.processAttributeValueTemplate(i,t);s.setAttributeNS(h,r,a)}else s.setAttribute(r,a)}xslIf(e,t,s){let r=e.getAttribute("test"),i=this.evaluateXPath(r,t);this.xpathEvaluator.toBoolean(i)&&this.processChildren(e,t,s)}xslChoose(e,t,s){for(let r of e.childNodes)if(r.nodeType===1){if(this.isXsltElement(r,"when")){let i=r.getAttribute("test"),n=this.evaluateXPath(i,t);if(this.xpathEvaluator.toBoolean(n)){this.processChildren(r,t,s);return}}else if(this.isXsltElement(r,"otherwise")){this.processChildren(r,t,s);return}}}xslForEach(e,t,s){let r=e.getAttribute("select"),i=this.evaluateXPath(r,t);Array.isArray(i)||(i=i?[i]:[]);let n=[];for(let a of e.childNodes)a.nodeType===1&&this.isXsltElement(a,"sort")&&n.push({select:a.getAttribute("select")||".",order:a.getAttribute("order")||"ascending",dataType:a.getAttribute("data-type")||"text",caseOrder:a.getAttribute("case-order")||"upper-first",lang:a.getAttribute("lang")});n.length>0&&(i=this.sortNodes(i,n,t));for(let a=0;a<i.length;a++){let l=t.clone({currentNode:i[a],currentNodeList:i,position:a+1});this.processChildren(e,l,s)}}xslCopy(e,t,s){let r=t.currentNode,i=e.getAttribute("use-attribute-sets");switch(r.nodeType){case 1:{let n;r.namespaceURI?n=t.outputDocument.createElementNS(r.namespaceURI,r.nodeName):n=t.outputDocument.createElement(r.nodeName),i&&this.applyAttributeSets(i,t,n),this.processChildren(e,t,n),s.appendChild(n);break}case 2:s.nodeType===1&&s.setAttribute(r.name,r.value);break;case 3:case 4:{let n=t.outputDocument.createTextNode(r.nodeValue||"");s.appendChild(n);break}case 7:{let n=t.outputDocument.createProcessingInstruction(r.target,r.data);s.appendChild(n);break}case 8:{let n=t.outputDocument.createComment(r.nodeValue||"");s.appendChild(n);break}case 9:case 11:this.processChildren(e,t,s);break}}xslCopyOf(e,t,s){let r=e.getAttribute("select"),i=this.evaluateXPath(r,t);this.copyToOutput(i,t,s)}copyToOutput(e,t,s){if(Array.isArray(e)){for(let r of e)this.copyToOutput(r,t,s);return}if(e&&e.nodeType){let r=this.deepCloneNode(e,t.outputDocument);s.appendChild(r)}else if(typeof e=="string"||typeof e=="number"||typeof e=="boolean"){let r=t.outputDocument.createTextNode(String(e));s.appendChild(r)}}deepCloneNode(e,t){switch(e.nodeType){case 1:{let s;if(e.namespaceURI&&t.createElementNS?s=t.createElementNS(e.namespaceURI,e.nodeName):s=t.createElement(e.nodeName),e.attributes)for(let r of e.attributes)s.setAttribute(r.name,r.value);for(let r of e.childNodes)s.appendChild(this.deepCloneNode(r,t));return s}case 3:case 4:return t.createTextNode(e.nodeValue||"");case 7:return t.createProcessingInstruction(e.target,e.data);case 8:return t.createComment(e.nodeValue||"");case 11:{let s=t.createDocumentFragment();for(let r of e.childNodes)s.appendChild(this.deepCloneNode(r,t));return s}default:return t.createTextNode("")}}xslVariable(e,t,s){let r=e.getAttribute("name"),i=e.getAttribute("select"),n;if(i)n=this.evaluateXPath(i,t);else{let a=t.outputDocument.createDocumentFragment();this.processChildren(e,t,a),n=a}t.setVariable(r,n)}xslComment(e,t,s){let r=t.outputDocument.createDocumentFragment();this.processChildren(e,t,r);let i="",n=l=>{if(l.nodeType===3||l.nodeType===4)i+=l.nodeValue||"";else if(l.childNodes)for(let h of l.childNodes)n(h)};n(r);let a=t.outputDocument.createComment(i);s.appendChild(a)}xslProcessingInstruction(e,t,s){let r=this.processAttributeValueTemplate(e.getAttribute("name"),t),i=t.outputDocument.createDocumentFragment();this.processChildren(e,t,i);let n="",a=h=>{if(h.nodeType===3||h.nodeType===4)n+=h.nodeValue||"";else if(h.childNodes)for(let p of h.childNodes)a(p)};a(i);let l=t.outputDocument.createProcessingInstruction(r,n);s.appendChild(l)}xslNumber(e,t,s){let r=e.getAttribute("value"),i=e.getAttribute("format")||"1",n=e.getAttribute("level")||"single",a;r?a=Math.round(this.xpathEvaluator.toNumber(this.evaluateXPath(r,t))):a=this.countNumber(t.currentNode,n,e,t);let l=this.formatNumber(a,i),h=t.outputDocument.createTextNode(l);s.appendChild(h)}countNumber(e,t,s,r){let i=s.getAttribute("count"),n=s.getAttribute("from");if(t==="single"){let a=1,l=e.previousSibling;for(;l;)l.nodeType===1&&(!i||this.matchesPattern(l,i,r))&&a++,l=l.previousSibling;return a}return 1}formatNumber(e,t){return/^[0-9]+$/.test(t)?String(e).padStart(t.length,"0"):t==="a"?String.fromCharCode(96+(e-1)%26+1):t==="A"?String.fromCharCode(64+(e-1)%26+1):t==="i"?this.toRoman(e).toLowerCase():t==="I"?this.toRoman(e):String(e)}toRoman(e){let t=[["M",1e3],["CM",900],["D",500],["CD",400],["C",100],["XC",90],["L",50],["XL",40],["X",10],["IX",9],["V",5],["IV",4],["I",1]],s="";for(let[r,i]of t)for(;e>=i;)s+=r,e-=i;return s}xslMessage(e,t,s){let r=e.getAttribute("terminate")==="yes",i=t.outputDocument.createDocumentFragment();this.processChildren(e,t,i);let n="",a=l=>{if(l.nodeType===3||l.nodeType===4)n+=l.nodeValue||"";else if(l.childNodes)for(let h of l.childNodes)a(h)};if(a(i),console.log("XSLT Message:",n),r)throw new Error(`XSLT terminated: ${n}`)}applyAttributeSets(e,t,s){let r=e.split(/\s+/).filter(Boolean);for(let i of r){let n=this.attributeSets[i];if(n){n.useAttributeSets.length>0&&this.applyAttributeSets(n.useAttributeSets.join(" "),t,s);for(let a of n.node.childNodes)a.nodeType===1&&this.isXsltElement(a,"attribute")&&this.xslAttribute(a,t,s)}}}sortNodes(e,t,s){return[...e].sort((r,i)=>{for(let n of t){let a=s.clone({currentNode:r}),l=s.clone({currentNode:i}),h=this.evaluateXPath(n.select,a),p=this.evaluateXPath(n.select,l);h=this.xpathEvaluator.toString(h)||"",p=this.xpathEvaluator.toString(p)||"",n.dataType==="number"?(h=parseFloat(h)||0,p=parseFloat(p)||0):n.caseOrder==="lower-first"?(h=h.toLowerCase(),p=p.toLowerCase()):(h=h.toUpperCase(),p=p.toUpperCase());let d;if(typeof h=="number"?d=h-p:d=h.localeCompare(p,n.lang||void 0),n.order==="descending"&&(d=-d),d!==0)return d}return 0})}evaluateXPath(e,t){let s=T(e),r=new E(t.currentNode,t.position,t.currentNodeList.length,{...t.variables,...t.parameters},t.namespaces);return this.xpathEvaluator.evaluate(s,r)}isXsltNamespace(e){return e.namespaceURI===N||e.nodeName&&e.nodeName.startsWith("xsl:")}isXsltElement(e,t){if(e.nodeType!==1)return!1;let s=e.localName||e.nodeName;return e.namespaceURI===N&&s===t||e.nodeName===`xsl:${t}`}};var y=class{constructor(){this._engine=null,this._stylesheet=null,this._parameters=new Map}importStylesheet(e){if(!e)throw new TypeError("Failed to execute 'importStylesheet' on 'XSLTProcessor': 1 argument required, but only 0 present.");if(e.nodeType!==1&&e.nodeType!==9)throw new TypeError("Failed to execute 'importStylesheet' on 'XSLTProcessor': The node provided is not a Document or Element.");if(e.querySelector?e.querySelector("parsererror"):null)throw new Error("XSLT stylesheet contains parse errors");this._stylesheet=e,this._engine=new A;for(let[s,r]of this._parameters)this._engine.globalParameters[s]={value:r};this._engine.importStylesheet(e)}transformToFragment(e,t){if(!e)throw new TypeError("Failed to execute 'transformToFragment' on 'XSLTProcessor': 2 arguments required, but only 0 present.");if(!t)throw new TypeError("Failed to execute 'transformToFragment' on 'XSLTProcessor': 2 arguments required, but only 1 present.");if(!this._engine||!this._stylesheet)throw new Error("Failed to execute 'transformToFragment' on 'XSLTProcessor': No stylesheet has been imported.");if(e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)throw new TypeError("Failed to execute 'transformToFragment' on 'XSLTProcessor': The source is not a valid node type.");if(t.nodeType!==9)throw new TypeError("Failed to execute 'transformToFragment' on 'XSLTProcessor': The output is not a Document.");try{return this._engine.transform(e,t)}catch(s){return console.error("XSLT transformation error:",s),null}}transformToDocument(e){if(!e)throw new TypeError("Failed to execute 'transformToDocument' on 'XSLTProcessor': 1 argument required, but only 0 present.");if(!this._engine||!this._stylesheet)throw new Error("Failed to execute 'transformToDocument' on 'XSLTProcessor': No stylesheet has been imported.");if(e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)throw new TypeError("Failed to execute 'transformToDocument' on 'XSLTProcessor': The source is not a valid node type.");try{return this._engine.transformToDocument(e)}catch(t){return console.error("XSLT transformation error:",t),null}}setParameter(e,t,s){if(arguments.length<3)throw new TypeError(`Failed to execute 'setParameter' on 'XSLTProcessor': 3 arguments required, but only ${arguments.length} present.`);if(typeof t!="string"||t==="")throw new TypeError("Failed to execute 'setParameter' on 'XSLTProcessor': The localName argument must be a non-empty string.");let r=e?`{${e}}${t}`:t;this._parameters.set(r,s),this._engine&&(this._engine.globalParameters[r]={value:s})}getParameter(e,t){if(arguments.length<2)throw new TypeError(`Failed to execute 'getParameter' on 'XSLTProcessor': 2 arguments required, but only ${arguments.length} present.`);if(typeof t!="string")throw new TypeError("Failed to execute 'getParameter' on 'XSLTProcessor': The localName argument must be a string.");let s=e?`{${e}}${t}`:t;return this._parameters.has(s)?this._parameters.get(s):""}removeParameter(e,t){if(arguments.length<2)throw new TypeError(`Failed to execute 'removeParameter' on 'XSLTProcessor': 2 arguments required, but only ${arguments.length} present.`);if(typeof t!="string")throw new TypeError("Failed to execute 'removeParameter' on 'XSLTProcessor': The localName argument must be a string.");let s=e?`{${e}}${t}`:t;this._parameters.delete(s),this._engine&&delete this._engine.globalParameters[s]}clearParameters(){this._parameters.clear(),this._engine&&(this._engine.globalParameters={})}reset(){this._engine=null,this._stylesheet=null,this._parameters.clear()}};function _(){if(typeof globalThis.XSLTProcessor>"u")return!1;try{let m=new globalThis.XSLTProcessor,e=new DOMParser,t=e.parseFromString(`<?xml version="1.0"?>
|
|
2
2
|
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
|
3
3
|
<xsl:template match="/"><test/></xsl:template>
|
|
4
4
|
</xsl:stylesheet>`,"application/xml");m.importStylesheet(t);let s=e.parseFromString("<root/>","application/xml"),r=m.transformToFragment(s,document);return r!==null&&r.childNodes.length>0}catch{return!1}}function k(m=!1){return!m&&_()?!1:(globalThis.XSLTProcessor=y,!0)}var I=y;function O(m,e,t={}){let s=T(m),r=new g,i=new E(e,1,1,t.variables||{},t.namespaces||{});return r.evaluate(s,i)}function D(m,e,t={}){let s=O(m,e,t);return Array.isArray(s)?s:s&&s.nodeType?[s]:[]}function U(m,e,t={}){let s=D(m,e,t);return s.length>0?s[0]:null}var K="1.0.0",Q=typeof window<"u"&&typeof document<"u",W=typeof process<"u"&&process.versions!=null&&process.versions.node!=null;return H(j);})();
|