@tradik/xslt-processor 1.0.3 → 1.1.1

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.
Files changed (47) hide show
  1. package/README.md +290 -45
  2. package/bin/lib/options.js +114 -0
  3. package/bin/lib/paths.js +186 -0
  4. package/bin/lib/transform.js +115 -0
  5. package/bin/xslt.js +68 -162
  6. package/dist/xslt-processor.browser.js +2074 -159
  7. package/dist/xslt-processor.browser.js.map +4 -4
  8. package/dist/xslt-processor.browser.min.js +6 -2
  9. package/dist/xslt-processor.browser.min.js.map +4 -4
  10. package/dist/xslt-processor.cjs +2078 -158
  11. package/dist/xslt-processor.cjs.map +4 -4
  12. package/dist/xslt-processor.d.cts +299 -0
  13. package/dist/xslt-processor.d.ts +92 -4
  14. package/dist/xslt-processor.js +2073 -157
  15. package/dist/xslt-processor.js.map +4 -4
  16. package/package.json +26 -15
  17. package/src/XSLTProcessor.js +177 -8
  18. package/src/index.js +11 -5
  19. package/src/xpath/evaluator.js +48 -7
  20. package/src/xslt/elements.js +57 -0
  21. package/src/xslt/engine.js +471 -179
  22. package/src/xslt/formatNumber.js +220 -0
  23. package/src/xslt/functions.js +191 -0
  24. package/src/xslt/index.js +31 -0
  25. package/src/xslt/keys.js +141 -0
  26. package/src/xslt/literalResult.js +167 -0
  27. package/src/xslt/number.js +178 -0
  28. package/src/xslt/numberFormat.js +155 -0
  29. package/src/xslt/resultTree.js +74 -0
  30. package/src/xslt/serializer/baseWriter.js +283 -0
  31. package/src/xslt/serializer/constants.js +78 -0
  32. package/src/xslt/serializer/escape.js +98 -0
  33. package/src/xslt/serializer/htmlSerializer.js +141 -0
  34. package/src/xslt/serializer/indent.js +51 -0
  35. package/src/xslt/serializer/namespaces.js +68 -0
  36. package/src/xslt/serializer/rawText.js +41 -0
  37. package/src/xslt/serializer/settings.js +103 -0
  38. package/src/xslt/serializer/textSerializer.js +29 -0
  39. package/src/xslt/serializer/xmlSerializer.js +127 -0
  40. package/src/xslt/serializer.js +57 -0
  41. package/src/xslt/templatePriority.js +45 -0
  42. package/src/xslt/uri.js +68 -0
  43. package/src/xslt/whitespace.js +184 -0
  44. package/src/XSLTProcessor.test.js +0 -930
  45. package/src/xpath/evaluator.test.js +0 -1852
  46. package/src/xpath/tokenizer.test.js +0 -224
  47. package/src/xslt/engine.test.js +0 -3130
@@ -1,6 +1,10 @@
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],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 K=Object.defineProperty;var qe=Object.getOwnPropertyDescriptor;var je=Object.getOwnPropertyNames;var Ke=Object.prototype.hasOwnProperty;var Qe=(o,e)=>{for(var t in e)K(o,t,{get:e[t],enumerable:!0})},Ze=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of je(e))!Ke.call(o,s)&&s!==t&&K(o,s,{get:()=>e[s],enumerable:!(r=qe(e,s))||r.enumerable});return o};var Je=o=>Ze(K({},"__esModule",{value:!0}),o);var Ft={};Qe(Ft,{VERSION:()=>kt,XPathContext:()=>T,XPathEvaluator:()=>N,XPathResultType:()=>Z,XSLTProcessor:()=>_,XsltContext:()=>v,XsltEngine:()=>b,default:()=>We,evaluateXPath:()=>fe,installGlobal:()=>He,isBrowser:()=>Mt,isNativeXSLTSupported:()=>me,isNode:()=>Ut,isRawText:()=>L,markRawText:()=>G,parseXPath:()=>S,resolveOutputSettings:()=>P,selectFirstXPath:()=>Ge,selectXPath:()=>de,serializeResult:()=>U});var c={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"},et=new Set(["ancestor","ancestor-or-self","attribute","child","descendant","descendant-or-self","following","following-sibling","namespace","parent","preceding","preceding-sibling","self"]),tt=new Set(["comment","text","processing-instruction","node"]),rt=new Set(["and","or","mod","div"]),E=class{constructor(e,t,r){this.type=e,this.value=t,this.position=r}toString(){return`Token(${this.type}, ${JSON.stringify(this.value)}, pos=${this.position})`}},st=new Set([c.AT,c.DOUBLE_COLON,c.LPAREN,c.LBRACKET,c.COMMA,c.SLASH,c.DOUBLE_SLASH,c.PIPE,c.PLUS,c.MINUS,c.STAR,c.DIV,c.MOD,c.EQUALS,c.NOT_EQUALS,c.LT,c.LTE,c.GT,c.GTE,c.AND,c.OR]),F=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||st.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 E(c.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 E(c.DOUBLE_SLASH,"//",e);if(t==="."&&this.peek(1)===".")return this.position+=2,new E(c.DOUBLE_DOT,"..",e);if(t===":"&&this.peek(1)===":")return this.position+=2,new E(c.DOUBLE_COLON,"::",e);if(t==="!"&&this.peek(1)==="=")return this.position+=2,new E(c.NOT_EQUALS,"!=",e);if(t==="<"&&this.peek(1)==="=")return this.position+=2,new E(c.LTE,"<=",e);if(t===">"&&this.peek(1)==="=")return this.position+=2,new E(c.GTE,">=",e);let r={"/":c.SLASH,"|":c.PIPE,"+":c.PLUS,"-":c.MINUS,"*":c.STAR,"=":c.EQUALS,"<":c.LT,">":c.GT,"(":c.LPAREN,")":c.RPAREN,"[":c.LBRACKET,"]":c.RBRACKET,"@":c.AT,".":c.DOT,",":c.COMMA,$:c.DOLLAR,":":c.COLON};if(r[t])return this.position++,new E(r[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(),r="";for(;this.position<this.expression.length&&this.peek()!==t;)r+=this.consume();if(this.position>=this.expression.length)throw new Error(`Unterminated string literal at position ${e}`);return this.consume(),new E(c.LITERAL,r,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 E(c.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(),et.has(t)&&this.peek()===":"&&this.peek(1)===":")return new E(c.AXIS,t,e);let r=this.position;if(this.skipWhitespace(),this.peek()==="(")return tt.has(t)?new E(c.NODE_TYPE,t,e):new E(c.FUNCTION,t,e);if(this.position=r,rt.has(t)&&this.isOperatorContext()){let s={and:c.AND,or:c.OR,mod:c.MOD,div:c.DIV};return new E(s[t],t,e)}return new E(c.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 Q(o){return new F(o).tokenize()}var p={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"},m=class{constructor(e,t={}){this.type=e,Object.assign(this,t)}},$=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(c.OR);){let t=this.parseAndExpr();e=new m(p.OR_EXPR,{left:e,right:t})}return e}parseAndExpr(){let e=this.parseEqualityExpr();for(;this.match(c.AND);){let t=this.parseEqualityExpr();e=new m(p.AND_EXPR,{left:e,right:t})}return e}parseEqualityExpr(){let e=this.parseRelationalExpr();for(;;)if(this.match(c.EQUALS)){let t=this.parseRelationalExpr();e=new m(p.EQUALITY_EXPR,{operator:"=",left:e,right:t})}else if(this.match(c.NOT_EQUALS)){let t=this.parseRelationalExpr();e=new m(p.EQUALITY_EXPR,{operator:"!=",left:e,right:t})}else break;return e}parseRelationalExpr(){let e=this.parseAdditiveExpr();for(;;)if(this.match(c.LT)){let t=this.parseAdditiveExpr();e=new m(p.RELATIONAL_EXPR,{operator:"<",left:e,right:t})}else if(this.match(c.LTE)){let t=this.parseAdditiveExpr();e=new m(p.RELATIONAL_EXPR,{operator:"<=",left:e,right:t})}else if(this.match(c.GT)){let t=this.parseAdditiveExpr();e=new m(p.RELATIONAL_EXPR,{operator:">",left:e,right:t})}else if(this.match(c.GTE)){let t=this.parseAdditiveExpr();e=new m(p.RELATIONAL_EXPR,{operator:">=",left:e,right:t})}else break;return e}parseAdditiveExpr(){let e=this.parseMultiplicativeExpr();for(;;)if(this.match(c.PLUS)){let t=this.parseMultiplicativeExpr();e=new m(p.ADDITIVE_EXPR,{operator:"+",left:e,right:t})}else if(this.match(c.MINUS)){let t=this.parseMultiplicativeExpr();e=new m(p.ADDITIVE_EXPR,{operator:"-",left:e,right:t})}else break;return e}parseMultiplicativeExpr(){let e=this.parseUnaryExpr();for(;;)if(this.match(c.STAR)){let t=this.parseUnaryExpr();e=new m(p.MULTIPLICATIVE_EXPR,{operator:"*",left:e,right:t})}else if(this.match(c.DIV)){let t=this.parseUnaryExpr();e=new m(p.MULTIPLICATIVE_EXPR,{operator:"div",left:e,right:t})}else if(this.match(c.MOD)){let t=this.parseUnaryExpr();e=new m(p.MULTIPLICATIVE_EXPR,{operator:"mod",left:e,right:t})}else break;return e}parseUnaryExpr(){if(this.match(c.MINUS)){let e=this.parseUnaryExpr();return new m(p.UNARY_EXPR,{operator:"-",operand:e})}return this.parseUnionExpr()}parseUnionExpr(){let e=this.parsePathExpr();for(;this.match(c.PIPE);){let t=this.parsePathExpr();e=new m(p.UNION_EXPR,{left:e,right:t})}return e}parsePathExpr(){if(this.check(c.SLASH)||this.check(c.DOUBLE_SLASH))return this.parseLocationPath();if(this.isStepStart())return this.parseLocationPath();let e=this.parseFilterExpr();if(this.check(c.SLASH)||this.check(c.DOUBLE_SLASH)){let t=[];for(;this.check(c.SLASH)||this.check(c.DOUBLE_SLASH);){let r=this.match(c.DOUBLE_SLASH);r||this.advance(),r&&t.push(new m(p.STEP,{axis:"descendant-or-self",nodeTest:new m(p.NODE_TYPE_TEST,{nodeType:"node"}),predicates:[]})),t.push(this.parseStep())}return new m(p.PATH_EXPR,{filter:e,steps:t})}return e}parseLocationPath(){let e=!1,t=[];for(this.match(c.DOUBLE_SLASH)?(e=!0,t.push(new m(p.STEP,{axis:"descendant-or-self",nodeTest:new m(p.NODE_TYPE_TEST,{nodeType:"node"}),predicates:[]})),!this.isAtEnd()&&!this.check(c.EOF)&&t.push(this.parseStep())):this.match(c.SLASH)?(e=!0,this.isStepStart()&&t.push(this.parseStep())):t.push(this.parseStep());this.check(c.SLASH)||this.check(c.DOUBLE_SLASH);){let r=this.match(c.DOUBLE_SLASH);r||this.advance(),r&&t.push(new m(p.STEP,{axis:"descendant-or-self",nodeTest:new m(p.NODE_TYPE_TEST,{nodeType:"node"}),predicates:[]})),t.push(this.parseStep())}return new m(p.LOCATION_PATH,{absolute:e,steps:t})}parseStep(){if(this.match(c.DOT))return new m(p.STEP,{axis:"self",nodeTest:new m(p.NODE_TYPE_TEST,{nodeType:"node"}),predicates:[]});if(this.match(c.DOUBLE_DOT))return new m(p.STEP,{axis:"parent",nodeTest:new m(p.NODE_TYPE_TEST,{nodeType:"node"}),predicates:[]});let e="child";this.match(c.AT)?e="attribute":this.check(c.AXIS)&&(e=this.advance().value,this.expect(c.DOUBLE_COLON));let t=this.parseNodeTest(),r=[];for(;this.check(c.LBRACKET);)r.push(this.parsePredicate());return new m(p.STEP,{axis:e,nodeTest:t,predicates:r})}parseNodeTest(){if(this.check(c.NODE_TYPE)){let e=this.advance().value;if(this.expect(c.LPAREN),e==="processing-instruction"&&this.check(c.LITERAL)){let t=this.advance().value;return this.expect(c.RPAREN),new m(p.PI_TEST,{name:t})}return this.expect(c.RPAREN),new m(p.NODE_TYPE_TEST,{nodeType:e})}return this.parseNameTest()}parseNameTest(){if(this.match(c.STAR))return new m(p.NAME_TEST,{name:"*",prefix:null});if(!this.check(c.NAME))throw new Error(`Expected name at position ${this.peek().position}`);let e=this.advance().value;if(this.match(c.COLON)){if(this.match(c.STAR))return new m(p.NAME_TEST,{name:"*",prefix:e});if(this.check(c.NAME)){let t=this.advance().value;return new m(p.NAME_TEST,{name:t,prefix:e})}throw new Error(`Expected name or * after : at position ${this.peek().position}`)}return new m(p.NAME_TEST,{name:e,prefix:null})}parsePredicate(){this.expect(c.LBRACKET);let e=this.parseExpr();return this.expect(c.RBRACKET),new m(p.PREDICATE,{expr:e})}parseFilterExpr(){let e=this.parsePrimaryExpr();for(;this.check(c.LBRACKET);){let t=this.parsePredicate();e=new m(p.PATH_EXPR,{filter:e,predicates:[t]})}return e}parsePrimaryExpr(){if(this.match(c.DOLLAR)){if(!this.check(c.NAME))throw new Error(`Expected variable name at position ${this.peek().position}`);let e=this.advance().value,t=null;if(this.match(c.COLON)){if(t=e,!this.check(c.NAME))throw new Error(`Expected local name at position ${this.peek().position}`);let r=this.advance().value;return new m(p.VARIABLE_REF,{name:r,prefix:t})}return new m(p.VARIABLE_REF,{name:e,prefix:t})}if(this.match(c.LPAREN)){let e=this.parseExpr();return this.expect(c.RPAREN),e}if(this.check(c.LITERAL))return new m(p.LITERAL,{value:this.advance().value});if(this.check(c.NUMBER))return new m(p.NUMBER,{value:this.advance().value});if(this.check(c.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(c.LPAREN);let r=[];if(!this.check(c.RPAREN))for(r.push(this.parseExpr());this.match(c.COMMA);)r.push(this.parseExpr());return this.expect(c.RPAREN),new m(p.FUNCTION_CALL,{name:e,prefix:t,args:r})}isStepStart(){let e=this.peek().type;return e===c.NAME||e===c.STAR||e===c.AT||e===c.DOT||e===c.DOUBLE_DOT||e===c.AXIS||e===c.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===c.EOF}};function S(o){let e=Q(o);return new $(e).parse()}var Z={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},V={MAX_RECURSION_DEPTH:100,MAX_RESULT_SIZE:1e4,MAX_STRING_LENGTH:1e6},Ee=Object.freeze(["__proto__","constructor","prototype","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__"]),T=class o{constructor(e,t=1,r=1,s={},n={},i=null){this.node=e,this.position=t,this.size=r,this.variables=s,this.namespaces=n,this.hostContext=i}clone(e={}){return new o(e.node??this.node,e.position??this.position,e.size??this.size,e.variables??this.variables,e.namespaces??this.namespaces,e.hostContext??this.hostContext)}},N=class{constructor(e={}){this.functions=Object.assign(Object.create(null),this.initCoreFunctions()),this.maxRecursionDepth=e.maxRecursionDepth??V.MAX_RECURSION_DEPTH,this.maxResultSize=e.maxResultSize??V.MAX_RESULT_SIZE,this.maxStringLength=e.maxStringLength??V.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 p.OR_EXPR:return this.evalOrExpr(e,t);case p.AND_EXPR:return this.evalAndExpr(e,t);case p.EQUALITY_EXPR:return this.evalEqualityExpr(e,t);case p.RELATIONAL_EXPR:return this.evalRelationalExpr(e,t);case p.ADDITIVE_EXPR:return this.evalAdditiveExpr(e,t);case p.MULTIPLICATIVE_EXPR:return this.evalMultiplicativeExpr(e,t);case p.UNARY_EXPR:return this.evalUnaryExpr(e,t);case p.UNION_EXPR:return this.evalUnionExpr(e,t);case p.PATH_EXPR:return this.evalPathExpr(e,t);case p.LOCATION_PATH:return this.evalLocationPath(e,t);case p.VARIABLE_REF:return this.evalVariableRef(e,t);case p.LITERAL:return this.validateString(e.value);case p.NUMBER:return e.value;case p.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 r=this.evaluate(e.left,t),s=this.evaluate(e.right,t),n=this.compareValues(r,s,"=");return e.operator==="="?n:!n}evalRelationalExpr(e,t){let r=this.evaluate(e.left,t),s=this.evaluate(e.right,t);return this.compareValues(r,s,e.operator)}evalAdditiveExpr(e,t){let r=this.toNumber(this.evaluate(e.left,t)),s=this.toNumber(this.evaluate(e.right,t));return e.operator==="+"?r+s:r-s}evalMultiplicativeExpr(e,t){let r=this.toNumber(this.evaluate(e.left,t)),s=this.toNumber(this.evaluate(e.right,t));switch(e.operator){case"*":return r*s;case"div":return r/s;case"mod":return r%s;default:throw new Error(`Unknown multiplicative operator: ${e.operator}`)}}evalUnaryExpr(e,t){return-this.toNumber(this.evaluate(e.operand,t))}evalUnionExpr(e,t){let r=this.evaluate(e.left,t),s=this.evaluate(e.right,t),n=Array.isArray(r)?r:[r],i=Array.isArray(s)?s:[s],a=new Set,l=[];for(let u of[...n,...i])a.has(u)||(a.add(u),l.push(u));return this.validateResultSize(l),this.sortByDocumentOrder(l)}evalPathExpr(e,t){if(e.filter){let r=this.evaluate(e.filter,t);if(e.predicates)for(let s of e.predicates)r=this.filterByPredicate(r,s,t);if(e.steps)for(let s of e.steps)r=this.evalStepOnNodes(s,r,t);return r}return[]}evalLocationPath(e,t){let r;e.absolute?r=[t.node.ownerDocument||t.node]:r=[t.node];for(let s of e.steps)r=this.evalStepOnNodes(s,r,t),this.validateResultSize(r);return r}evalStepOnNodes(e,t,r){let s=Array.isArray(t)?t:[t],n=[];for(let a of s){let l=this.evalStep(e,r.clone({node:a}));n=n.concat(l),n.length>this.maxResultSize*2&&this.validateResultSize(n)}let i=[...new Set(n)];return this.validateResultSize(i),this.sortByDocumentOrder(i)}evalStep(e,t){let r=this.getAxisNodes(e.axis,t.node);r=r.filter(s=>this.matchNodeTest(e.nodeTest,s,t));for(let s of e.predicates)r=this.filterByPredicate(r,s,t);return r}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 r=t?[e]:[],s=Array.from(e.childNodes||[]).reverse();for(;s.length>0;){let n=s.pop();if(r.push(n),n.childNodes)for(let i=n.childNodes.length-1;i>=0;i--)s.push(n.childNodes[i])}return r}getAncestors(e,t){let r=t?[e]:[],s=e.parentNode;for(;s;)r.push(s),s=s.parentNode;return r}getFollowingSiblings(e){let t=[];if(!e)return t;let r=e.nextSibling;for(;r;)t.push(r),r=r.nextSibling;return t}getPrecedingSiblings(e){let t=[];if(!e)return t;let r=e.previousSibling;for(;r;)t.push(r),r=r.previousSibling;return t.reverse()}getFollowing(e){let t=[],r=e;for(;r;)r.nextSibling?(r=r.nextSibling,t.push(r),t.push(...this.getDescendants(r,!1))):r=r.parentNode;return t}getPreceding(e){let t=[],r=e;for(;r;)if(r.previousSibling){r=r.previousSibling;let s=this.getDescendants(r,!1);t.unshift(...s.reverse()),t.unshift(r)}else r=r.parentNode,r&&r.nodeType;return t}matchNodeTest(e,t,r){switch(e.type){case p.NAME_TEST:return this.matchNameTest(e,t,r);case p.NODE_TYPE_TEST:return this.matchNodeTypeTest(e.nodeType,t);case p.PI_TEST:return t.nodeType===7&&t.nodeName===e.name;default:return!1}}matchNameTest(e,t,r){if(t.nodeType!==1&&t.nodeType!==2)return!1;let s=e.name,n=e.prefix;if(s==="*"&&!n)return!0;let i=t.localName||t.nodeName,a=t.namespaceURI||null;if(s==="*"&&n){let u=r.namespaces[n];return a===u}if(!n){let u=t.ownerDocument;return u&&u.contentType==="text/html"&&t.nodeType===1?i.toLowerCase()===s.toLowerCase():i===s}let l=r.namespaces[n];return i===s&&a===l}matchNodeTypeTest(e,t){switch(e){case"node":return!0;case"text":return t.nodeType===3||t.nodeType===4;case"comment":return t.nodeType===8;case"processing-instruction":return t.nodeType===7;default:return!1}}filterByPredicate(e,t,r){let s=[],n=Array.isArray(e)?e:[e],i=n.length;for(let a=0;a<n.length;a++){let l=n[a],u=r.clone({node:l,position:a+1,size:i}),h=this.evaluate(t.expr,u);typeof h=="number"?h===a+1&&s.push(l):this.toBoolean(h)&&s.push(l)}return s}evalVariableRef(e,t){let r=e.prefix?`${e.prefix}:${e.name}`:e.name;if(Ee.includes(r)||Ee.includes(e.name))throw new Error(`Forbidden variable name: $${r}`);if(!Object.prototype.hasOwnProperty.call(t.variables,r))throw new Error(`Undefined variable: $${r}`);return t.variables[r]}registerFunctions(e){for(let[t,r]of Object.entries(e))this.functions[t]=r;return this}evalFunctionCall(e,t){let r=e.prefix?`${e.prefix}:${e.name}`:e.name;if(!Object.hasOwn(this.functions,r))throw new Error(`Unknown function: ${r}`);return this.functions[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="",r=s=>{if(s.nodeType===3||s.nodeType===4)t+=s.nodeValue||"";else if(s.childNodes)for(let n of s.childNodes)r(n)};return r(e),t}case 2:case 3:case 4:case 7:case 8:return e.nodeValue||"";default:return""}}compareValues(e,t,r){let s=Array.isArray(e),n=Array.isArray(t);if(s&&n){for(let i of e)for(let a of t)if(this.comparePrimitive(this.getStringValue(i),this.getStringValue(a),r))return!0;return!1}if(s){for(let i of e)if(this.comparePrimitive(this.getStringValue(i),t,r))return!0;return!1}if(n){for(let i of t)if(this.comparePrimitive(e,this.getStringValue(i),r))return!0;return!1}return this.comparePrimitive(e,t,r)}comparePrimitive(e,t,r){if(r==="="||r==="!="){if(typeof e=="boolean"||typeof t=="boolean"){let a=this.toBoolean(e)===this.toBoolean(t);return r==="="?a:!a}if(typeof e=="number"||typeof t=="number"){let a=this.toNumber(e)===this.toNumber(t);return r==="="?a:!a}let i=this.toString(e)===this.toString(t);return r==="="?i:!i}let s=this.toNumber(e),n=this.toNumber(t);switch(r){case"<":return s<n;case"<=":return s<=n;case">":return s>n;case">=":return s>=n;default:throw new Error(`Unknown comparison operator: ${r}`)}}sortByDocumentOrder(e){return e.length<=1?e:e.sort((t,r)=>{if(t===r)return 0;let s=t.compareDocumentPosition?t.compareDocumentPosition(r):this.compareDocumentPositionFallback(t,r);return s&4?-1:s&2?1:0})}compareDocumentPositionFallback(e,t){let r=i=>{let a=[],l=i;for(;l;){if(l.parentNode){let u=Array.from(l.parentNode.childNodes);a.unshift(u.indexOf(l))}l=l.parentNode}return a},s=r(e),n=r(t);for(let i=0;i<Math.min(s.length,n.length);i++){if(s[i]<n[i])return 4;if(s[i]>n[i])return 2}return s.length<n.length?4:2}initCoreFunctions(){return{last:(e,t)=>t.size,position:(e,t)=>t.position,count:(e,t)=>{let r=this.evaluate(e[0],t);return Array.isArray(r)?r.length:1},id:(e,t)=>{let r=this.toString(this.evaluate(e[0],t)),s=t.node.ownerDocument||t.node,n=r.split(/\s+/).filter(a=>a),i=[];for(let a of n){let l=s.getElementById(a);l&&i.push(l)}return i},"local-name":(e,t)=>{let r;if(e.length===0)r=t.node;else{let s=this.evaluate(e[0],t);r=Array.isArray(s)?s[0]:s}return r&&(r.localName||r.nodeName)||""},"namespace-uri":(e,t)=>{let r;if(e.length===0)r=t.node;else{let s=this.evaluate(e[0],t);r=Array.isArray(s)?s[0]:s}return r&&r.namespaceURI||""},name:(e,t)=>{let r;if(e.length===0)r=t.node;else{let s=this.evaluate(e[0],t);r=Array.isArray(s)?s[0]:s}return r&&r.nodeName||""},string:(e,t)=>e.length===0?this.toString([t.node]):this.toString(this.evaluate(e[0],t)),concat:(e,t)=>e.map(r=>this.toString(this.evaluate(r,t))).join(""),"starts-with":(e,t)=>{let r=this.toString(this.evaluate(e[0],t)),s=this.toString(this.evaluate(e[1],t));return r.startsWith(s)},contains:(e,t)=>{let r=this.toString(this.evaluate(e[0],t)),s=this.toString(this.evaluate(e[1],t));return r.includes(s)},"substring-before":(e,t)=>{let r=this.toString(this.evaluate(e[0],t)),s=this.toString(this.evaluate(e[1],t)),n=r.indexOf(s);return n===-1?"":r.substring(0,n)},"substring-after":(e,t)=>{let r=this.toString(this.evaluate(e[0],t)),s=this.toString(this.evaluate(e[1],t)),n=r.indexOf(s);return n===-1?"":r.substring(n+s.length)},substring:(e,t)=>{let r=this.toString(this.evaluate(e[0],t)),s=Math.round(this.toNumber(this.evaluate(e[1],t))),n;return e.length>2&&(n=Math.round(this.toNumber(this.evaluate(e[2],t)))),s=s-1,isNaN(s)?"":(s<0&&(n!==void 0&&(n=n+s),s=0),n!==void 0?isNaN(n)||n<=0?"":r.substring(s,s+n):r.substring(s))},"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 r=this.toString(this.evaluate(e[0],t)),s=this.toString(this.evaluate(e[1],t)),n=this.toString(this.evaluate(e[2],t)),i="";for(let a of r){let l=s.indexOf(a);l===-1?i+=a:l<n.length&&(i+=n[l])}return i},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 r=this.toString(this.evaluate(e[0],t)).toLowerCase(),s=t.node;for(;s&&s.nodeType===1;){let n=s.getAttribute("xml:lang")||s.getAttribute("lang");if(n){let i=n.toLowerCase();return i===r||i.startsWith(r+"-")}s=s.parentNode}return!1},number:(e,t)=>e.length===0?this.toNumber([t.node]):this.toNumber(this.evaluate(e[0],t)),sum:(e,t)=>{let r=this.evaluate(e[0],t);return Array.isArray(r)?r.reduce((s,n)=>s+this.toNumber(this.getStringValue(n)),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 r=this.toNumber(this.evaluate(e[0],t));return isNaN(r)?NaN:r===-.5?-0:Math.round(r)}}}};var x="http://www.w3.org/1999/XSL/Transform",ge=Object.freeze(["apply-imports","apply-templates","attribute","call-template","choose","comment","copy","copy-of","element","fallback","for-each","if","message","number","otherwise","param","processing-instruction","sort","text","value-of","variable","when","with-param"]),it=new Set(ge);function J(o){return it.has(o)}var D=Object.freeze({decimalSeparator:".",groupingSeparator:",",percent:"%",perMille:"\u2030",zeroDigit:"0",digit:"#",patternSeparator:";",infinity:"Infinity",nan:"NaN",minusSign:"-"});function nt(o,e){let t=o.indexOf(e.patternSeparator);return t===-1?{positive:o,negative:null}:{positive:o.substring(0,t),negative:o.substring(t+e.patternSeparator.length)}}function Te(o,e){let t=new Set([e.digit,e.zeroDigit,e.groupingSeparator,e.decimalSeparator]),r=0;for(;r<o.length&&!t.has(o[r]);)r++;let s=r;for(;s<o.length&&t.has(o[s]);)s++;let n=o.substring(0,r),i=o.substring(r,s),a=o.substring(s),l=i.indexOf(e.decimalSeparator),u=l===-1?i:i.substring(0,l),h=l===-1?"":i.substring(l+1),f=u.lastIndexOf(e.groupingSeparator),A=n+a,w=1;return A.includes(e.percent)?w=100:A.includes(e.perMille)&&(w=1e3),{prefix:n,suffix:a,multiplier:w,minInteger:Ae(u,e.zeroDigit),minFraction:Ae(h,e.zeroDigit),maxFraction:Math.min(h.length,100),groupingSize:f===-1?0:u.length-f-1}}function Ae(o,e){let t=0;for(let r of o)r===e&&t++;return t}function ot(o,e,t){if(e<=0||o.length<=e)return o;let r="";for(let s=0;s<o.length;s++){let n=o.length-s;s>0&&n%e===0&&(r+=t),r+=o[s]}return r}function at(o,e){let t=e.codePointAt(0)-48;return t===0?o:o.replaceAll(/\d/g,r=>String.fromCodePoint(r.codePointAt(0)+t))}function lt(o,e,t){let r=o.toFixed(e.maxFraction),[s,n=""]=r.split("."),i=n;for(;i.length>e.minFraction&&i.endsWith("0");)i=i.slice(0,-1);let a=s.padStart(e.minInteger,"0");e.minInteger===0&&a==="0"&&i.length>0&&(a=""),a=ot(a,e.groupingSize,t.groupingSeparator);let l=i.length>0?a+t.decimalSeparator+i:a;return at(l,t.zeroDigit)}function ee(o,e,t=D){let r={...D,...t};if(typeof o!="number"||Number.isNaN(o))return r.nan;let s=nt(e,r),n=Te(s.positive,r),i=o<0,a=n,l=n.prefix,u=n.suffix;i&&(s.negative!==null?(a=Te(s.negative,r),l=a.prefix,u=a.suffix):l=r.minusSign+n.prefix);let h=Math.abs(o)*a.multiplier,f=Number.isFinite(h)?lt(h,a,r):r.infinity;return l+f+u}var ye="@tradik/xslt-processor",be="https://github.com/spagu/XSLT-Processor",Ne=Object.freeze({"xsl:version":"1","xsl:vendor":ye,"xsl:vendor-url":be});function ct(o){return o.ownerDocument||o}function Se(o,e,t){return Array.isArray(t)?t.map(r=>o.getStringValue(r)):[e(t)]}function ut(o){let e=o.indexOf(":");return e===-1?{prefix:null,localName:o}:{prefix:o.substring(0,e),localName:o.substring(e+1)}}function te(o){let e=o.xpathEvaluator,t=e.toString.bind(e),r=(n,i)=>e.evaluate(n,i),s=(n,i)=>t(r(n,i));return{document:(n,i)=>{let a=n.length>1?s(n[1],i):o.baseUri,l=Se(e,t,r(n[0],i)),u=[];for(let h of l){let f=o.loadDocument(h,a||o.baseUri);f&&!u.includes(f)&&u.push(f)}return u},key:(n,i)=>{let a=s(n[0],i),l=Se(e,t,r(n[1],i));return o.keyRegistry.lookup(a,l,ct(i.node))},"format-number":(n,i)=>{let a=e.toNumber(r(n[0],i)),l=s(n[1],i),u=n.length>2?s(n[2],i):"",h=o.decimalFormats[u]||D;return ee(a,l,h)},current:(n,i)=>{let a=i.hostContext?.currentNode;return a?[a]:[i.node]},"generate-id":(n,i)=>{let a=i.node;if(n.length>0){let l=r(n[0],i);a=Array.isArray(l)?l[0]:l}return a?o.generateId(a):""},"system-property":(n,i)=>{let a=s(n[0],i);return Object.hasOwn(Ne,a)?Ne[a]:""},"function-available":(n,i)=>{let a=s(n[0],i);return Object.hasOwn(e.functions,a)},"element-available":(n,i)=>{let{prefix:a,localName:l}=ut(s(n[0],i));return a?(i.namespaces[a]??(a==="xsl"?x:null))===x&&J(l):!1},"unparsed-entity-uri":()=>""}}var O=class{constructor({keys:e,matchesPattern:t,evaluateUse:r}){this.keys=e,this.matchesPattern=t,this.evaluateUse=r,this.cache=new WeakMap}clear(){this.cache=new WeakMap}lookup(e,t,r){if(!Object.hasOwn(this.keys,e))throw new Error(`Undefined key: ${e}`);let s=this.getIndex(e,r),n=Array.isArray(t)?t:[t],i=[];for(let a of n)for(let l of s.get(a)||[])i.includes(l)||i.push(l);return i}getIndex(e,t){let r=this.cache.get(t);r||(r=new Map,this.cache.set(t,r));let s=r.get(e);return s||(s=this.buildIndex(e,t),r.set(e,s)),s}buildIndex(e,t){let{match:r,use:s}=this.keys[e],n=new Map;for(let i of ht(t))if(this.matchesPattern(i,r))for(let a of this.evaluateUse(i,s)){let l=n.get(a);l?l.push(i):n.set(a,[i])}return n}};function*ht(o){let e=[o];for(;e.length>0;){let t=e.pop();if(yield t,t.nodeType===1&&t.attributes)for(let s of t.attributes)yield s;let r=t.childNodes;if(r)for(let s=r.length-1;s>=0;s--)e.push(r[s])}}var we=new Set([1,3,4,7,8]);function pt(o,e){return o.nodeType!==e.nodeType?!1:o.nodeType===1?o.nodeName===e.nodeName:!0}function mt(o,e,t){return e?r=>t(r,e):r=>pt(r,o)}function ft(o,e){return o?t=>e(t,o):()=>!1}function xe(o,e){let t=1,r=o.previousSibling;for(;r;)we.has(r.nodeType)&&e(r)&&t++,r=r.previousSibling;return t}function dt(o){let e=o.ownerDocument||o,t=[],r=[e];for(;r.length>0;){let s=r.pop();if(t.push(s),s===o)break;let n=s.childNodes;if(n)for(let i=n.length-1;i>=0;i--)r.push(n[i])}return t}function Et(o,e,t){let r=o;for(;r&&r.nodeType!==9;){if(t(r))return[];if(e(r))return[xe(r,e)];r=r.parentNode}return[]}function gt(o,e,t){let r=[],s=o;for(;s&&s.nodeType!==9&&!t(s);)e(s)&&r.unshift(xe(s,e)),s=s.parentNode;return r}function Tt(o,e,t){let r=0;for(let s of dt(o))if(we.has(s.nodeType)){if(t(s)){r=0;continue}e(s)&&r++}return r>0?[r]:[]}function re(o,e,t){let{level:r="single",count:s=null,from:n=null}=e,i=mt(o,s,t),a=ft(n,t);return r==="any"?Tt(o,i,a):r==="multiple"?gt(o,i,a):Et(o,i,a)}function Pe(o,e){let t=o,r="";for(;t>0;){let s=(t-1)%26;r=String.fromCodePoint((e?65:97)+s)+r,t=Math.floor((t-1)/26)}return r}var At=Object.freeze([["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]]);function C(o){let e=o,t="";for(let[r,s]of At)for(;e>=s;)t+=r,e-=s;return t}function Nt(o,e){if(/^\d+$/.test(e))return String(o).padStart(e.length,"0");if(o<=0)return String(o);switch(e){case"a":return Pe(o,!1);case"A":return Pe(o,!0);case"i":return C(o).toLowerCase();case"I":return C(o);default:return String(o)}}function St(o){let e=o.match(/[a-zA-Z0-9]+|[^a-zA-Z0-9]+/g)||[],t=a=>/^[a-zA-Z0-9]+$/.test(a),r=[],s=[],n="",i="";for(let a of e)t(a)?r.push(a):r.length===0?n=a:s.push(a);return e.length>0&&r.length>0&&!t(e.at(-1))&&(i=s.pop()),r.length===0&&r.push("1"),{prefix:n,suffix:i,tokens:r,separators:s}}function B(o,e="1"){if(o.length===0)return"";let{prefix:t,suffix:r,tokens:s,separators:n}=St(e),i=t;return o.forEach((a,l)=>{if(l>0){let u=n[l-1]??n.at(-1)??".";i+=u}i+=Nt(a,s[l]??s.at(-1))}),i+r}var yt=/^[a-zA-Z][a-zA-Z0-9+.-]*:/;function z(o,e){if(!o||!e||Le(o)||o.startsWith("/"))return o;let t=e.lastIndexOf("/");return(t>=0?e.substring(0,t+1):"")+o}function Le(o){return yt.test(o)}function se(o){if(typeof o!="string")return"";let e=o.indexOf("#");return e===-1?o:o.substring(0,e)}function Re(o){return o==="*"?-.5:o.endsWith(":*")?-.25:0}function ve(o,e){if(e==="*")return!0;if(e.endsWith(":*")){let t=e.slice(0,-2);return o.nodeName.startsWith(`${t}:`)}return o.nodeName===e||o.localName===e}var I=class{constructor(e=[],t=[]){this.stripSpace=e,this.preserveSpace=t}isActive(){return this.stripSpace.length>0}isStripped(e){let t=-1/0,r=-1/0;for(let s of this.stripSpace)ve(e,s)&&(t=Math.max(t,Re(s)));for(let s of this.preserveSpace)ve(e,s)&&(r=Math.max(r,Re(s)));return t>-1/0&&t>r}};function bt(o){let e=o;for(;e?.nodeType===1;){let t=e.getAttribute("xml:space");if(t==="preserve")return!0;if(t==="default")return!1;e=e.parentNode}return!1}function wt(o,e){let t=[],r=[o];for(;r.length>0;){let s=r.pop();(s.nodeType===3||s.nodeType===4)&&s.nodeValue!==null&&s.nodeValue.trim()===""&&s.parentNode?.nodeType===1&&e.isStripped(s.parentNode)&&!bt(s.parentNode)&&t.push(s);let n=s.childNodes;if(n)for(let i=n.length-1;i>=0;i--)r.push(n[i])}for(let s of t)s.remove()}function ie(o,e,t){let r;if(o.nodeType===9){r=t;for(let s of Array.from(o.childNodes))s.nodeType!==10&&t.appendChild(t.importNode(s,!0))}else r=t.importNode(o,!0),t.appendChild(r);return wt(r,e),r}function ne(o,e){if(typeof o.lookupNamespaceURI=="function"){let s=o.lookupNamespaceURI(e);if(s)return s}let t=e?`xmlns:${e}`:"xmlns",r=o;for(;r?.nodeType===1;){let s=r.getAttribute(t);if(s)return s;r=r.parentNode}return null}var X=class{constructor(){this.byUri=new Map}add(e){let t=e.getAttribute("stylesheet-prefix"),r=e.getAttribute("result-prefix");if(!t||!r)return;let s=ne(e,t==="#default"?null:t);if(!s)return;let n=r==="#default",i=ne(e,n?null:r);this.byUri.set(s,{uri:i,prefix:n?null:r})}isEmpty(){return this.byUri.size===0}resolve(e,t){let r=e?this.byUri.get(e):void 0;return r?{namespaceUri:r.uri,qname:r.prefix?`${r.prefix}:${t}`:t}:null}};function oe(o,e){return o.namespaceURI===e||o.name==="xmlns"||o.name.startsWith("xmlns:")?!1:!o.name.startsWith("xsl:")}function ae(o,e,t){if(!o.attributes)return null;for(let r of o.attributes)if(r.namespaceURI===t&&(r.localName||r.name)===e||r.name===`xsl:${e}`)return r.value;return null}function Y(o){return o.implementation.createDocument(null,null,null)}function le(o,e){let t=e.importNode(o,!1);if(o._disableOutputEscaping&&(t._disableOutputEscaping=!0),o.childNodes)for(let r of o.childNodes)t.appendChild(le(r,e));return t}function ce(o,e){if(o.ownerDocument===e)return o;let t=e.createDocumentFragment();for(let r of o.childNodes)t.appendChild(le(r,e));return t}var ue=String.raw`[A-Za-z_][\w.-]*`,xt=`(?:${ue}:)?${ue}`,Pt=new RegExp(`^(?:child::|attribute::|@)?${xt}$`),Lt=new RegExp(String.raw`^(?:child::|attribute::|@)?${ue}:\*$`),Rt=/^(?:child::|attribute::|@)?(?:\*|node\(\)|text\(\)|comment\(\)|processing-instruction\(\))$/,vt=/^(?:child::)?processing-instruction\(\s*(?:"[^"]*"|'[^']*')\s*\)$/;function _e(o){return o?Rt.test(o)?-.5:Lt.test(o)?-.25:Pt.test(o)||vt.test(o)?0:.5:.5}var d={ELEMENT:1,TEXT:3,CDATA_SECTION:4,PROCESSING_INSTRUCTION:7,COMMENT:8,DOCUMENT:9,DOCUMENT_FRAGMENT:11},k="http://www.w3.org/2000/xmlns/",De="http://www.w3.org/XML/1998/namespace",g={ESCAPE:"escape",CDATA:"cdata",RAW:"raw"},Oe=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Ce=new Set(["script","style"]),Ie=new Set(["pre","script","style","textarea"]),he=" ";function Xe(o){return o===!0||String(o).toLowerCase()==="yes"}function _t(o){return Array.isArray(o)?new Set(o):typeof o=="string"?new Set(o.split(/\s+/).filter(Boolean)):new Set}function H(o){if(!o)return null;if(o.nodeType===d.ELEMENT)return o;for(let e of o.childNodes||[])if(e.nodeType===d.ELEMENT)return e;return null}function ke(o){let e=H(o);return e&&!e.namespaceURI&&e.localName.toLowerCase()==="html"?"html":"xml"}function P(o,e){let t=o||{},r=typeof t.method=="string"?t.method.trim():"";return{method:r&&r!=="auto"?r.toLowerCase():ke(e),version:t.version||"1.0",encoding:t.encoding||"UTF-8",standalone:t.standalone||null,indent:Xe(t.indent),omitXmlDeclaration:Xe(t.omitXmlDeclaration),doctypePublic:t.doctypePublic||null,doctypeSystem:t.doctypeSystem||null,mediaType:t.mediaType||null,cdataSectionElements:_t(t.cdataSectionElements)}}var Dt={"&":"&amp;","<":"&lt;"},Ot={"&":"&amp;","<":"&lt;",">":"&gt;"},Ct={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"," ":"&#9;","\n":"&#10;","\r":"&#13;"},It={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"};function W(o,e,t){return String(o).replaceAll(e,r=>t[r])}function Me(o){return W(o,/[&<]/g,Dt).replaceAll("]]>","]]&gt;")}function Ue(o){return W(o,/[&<>"\t\n\r]/g,Ct)}function Fe(o){return W(o,/[&<>]/g,Ot)}function $e(o){return W(o,/[&<>"]/g,It)}function Ve(o){return`<![CDATA[${String(o).replaceAll("]]>","]]]]><![CDATA[>")}]]>`}function Be(){return new Map([["",""],["xml",De]])}function ze(o,e){let t=[],r=e,s=(i,a)=>{r.get(i)!==a&&(r===e&&(r=new Map(e)),r.set(i,a),t.push({prefix:i,uri:a}))};s(o.prefix||"",o.namespaceURI||"");let n=Array.from(o.attributes||[]);for(let i of n)i.namespaceURI!==k&&i.prefix&&s(i.prefix,i.namespaceURI||"");for(let i of n)i.namespaceURI===k&&s(i.prefix?i.localName:"",i.value);return{declarations:t,scope:r}}function Xt(o){return!/\S/.test(o.nodeValue||"")}function Ye(o){let e=[];for(let t of o.childNodes){if(t.nodeType===d.TEXT){if(Xt(t))continue;return null}if(t.nodeType!==d.ELEMENT&&t.nodeType!==d.COMMENT&&t.nodeType!==d.PROCESSING_INSTRUCTION)return null;e.push(t)}return e.length>0?e:null}var pe=new WeakSet;function G(o){return o&&pe.add(o),o}function L(o){return o?pe.has(o)||o._disableOutputEscaping===!0:!1}var q=class{constructor(e,t={}){this.settings=e,this.xhtml=t.xhtml===!0,this.parts=[]}serialize(e){return this.parts=[],this.writeProlog(e),this.writeNode(e,Be(),0,g.ESCAPE),this.parts.join("")}writeProlog(e){if(this.emitsXmlDeclaration){let{version:r,encoding:s,standalone:n}=this.settings,i=n?` standalone="${n}"`:"";this.parts.push(`<?xml version="${r}" encoding="${s}"${i}?>
2
+ `)}let t=this.doctypeMarkup(H(e));t&&this.parts.push(`${t}
3
+ `)}writeNode(e,t,r,s){switch(e.nodeType){case d.ELEMENT:this.writeElement(e,t,r);break;case d.TEXT:case d.CDATA_SECTION:this.writeText(e,s);break;case d.COMMENT:this.parts.push(`<!--${e.nodeValue}-->`);break;case d.PROCESSING_INSTRUCTION:this.writeProcessingInstruction(e);break;case d.DOCUMENT:case d.DOCUMENT_FRAGMENT:this.writeChildNodes(e,t,r,s);break;default:break}}writeChildNodes(e,t,r,s){for(let n of e.childNodes)this.writeNode(n,t,r,s)}writeElement(e,t,r){let s=this.emitsNamespaces?ze(e,t):{declarations:[],scope:t},n=e.nodeName;if(this.parts.push(`<${n}${this.namespaceMarkup(s.declarations)}`+this.attributesMarkup(e)),!e.firstChild){this.parts.push(this.emptyElementMarkup(e,n));return}this.parts.push(">"),this.writeElementChildren(e,s.scope,r),this.parts.push(`</${n}>`)}writeElementChildren(e,t,r){let s=this.childTextMode(e),n=this.indentableChildren(e,s);if(!n){this.writeChildNodes(e,t,r,s);return}let i=`
4
+ ${he.repeat(r+1)}`;for(let a of n)this.parts.push(i),this.writeNode(a,t,r+1,s);this.parts.push(`
5
+ ${he.repeat(r)}`)}indentableChildren(e,t){return!this.settings.indent||t!==g.ESCAPE||!this.allowsIndentInside(e)?null:Ye(e)}namespaceMarkup(e){return e.map(({prefix:t,uri:r})=>` ${t?`xmlns:${t}`:"xmlns"}="${this.escapeAttribute(r)}"`).join("")}attributesMarkup(e){let t="";for(let r of Array.from(e.attributes||[]))r.namespaceURI!==k&&(t+=this.attributeMarkup(r));return t}attributeMarkup(e){return` ${e.name}="${this.escapeAttribute(e.value)}"`}writeText(e,t){let r=e.nodeValue||"";if(L(e)){this.parts.push(r);return}let s=this.resolveTextMode(e,t);s===g.CDATA?this.parts.push(Ve(r)):s===g.RAW?this.parts.push(r):this.parts.push(this.escapeText(r))}resolveTextMode(e,t){return t!==g.ESCAPE?t:e.nodeType===d.CDATA_SECTION?this.cdataNodeMode:g.ESCAPE}writeProcessingInstruction(e){let t=e.nodeValue||"",r=t?" ":"";this.parts.push(`<?${e.target}${r}${t}${this.piTerminator}`)}};var y=class extends q{get emitsXmlDeclaration(){return!this.settings.omitXmlDeclaration}get emitsNamespaces(){return!0}get piTerminator(){return"?>"}get cdataNodeMode(){return g.CDATA}doctypeMarkup(e){let{doctypePublic:t,doctypeSystem:r}=this.settings;if(!e||!r)return"";let s=e.nodeName;return t?`<!DOCTYPE ${s} PUBLIC "${t}" "${r}">`:`<!DOCTYPE ${s} SYSTEM "${r}">`}childTextMode(e){let t=this.settings.cdataSectionElements;return t.has(e.nodeName)||t.has(e.localName)?g.CDATA:g.ESCAPE}allowsIndentInside(e){return!0}emptyElementMarkup(e,t){return this.xhtml&&this.isVoidElement(e)?" />":"/>"}isVoidElement(e){return Oe.has(String(e.localName).toLowerCase())}escapeText(e){return Me(e)}escapeAttribute(e){return Ue(e)}};var M=class extends y{get emitsXmlDeclaration(){return!1}get emitsNamespaces(){return!1}get piTerminator(){return">"}get cdataNodeMode(){return g.ESCAPE}doctypeMarkup(e){let{doctypePublic:t,doctypeSystem:r}=this.settings;if(!t&&!r)return"";let s=e?e.nodeName:"html";return t&&r?`<!DOCTYPE ${s} PUBLIC "${t}" "${r}">`:t?`<!DOCTYPE ${s} PUBLIC "${t}">`:`<!DOCTYPE ${s} SYSTEM "${r}">`}childTextMode(e){return Ce.has(String(e.localName).toLowerCase())?g.RAW:g.ESCAPE}allowsIndentInside(e){return!Ie.has(String(e.localName).toLowerCase())}emptyElementMarkup(e,t){return this.isVoidElement(e)?">":`></${t}>`}attributeMarkup(e){let{name:t,value:r}=e;return String(r).toLowerCase()===t.toLowerCase()?` ${t}`:` ${t}="${this.escapeAttribute(r)}"`}escapeText(e){return Fe(e)}escapeAttribute(e){return $e(e)}};function j(o){if(o.nodeType===d.TEXT||o.nodeType===d.CDATA_SECTION)return o.nodeValue||"";let e="";for(let t of o.childNodes||[])e+=j(t);return e}function U(o,e={}){if(!o)return"";let t=P(e,o);return t.method==="text"?j(o):t.method==="html"?new M(t).serialize(o):new y(t,{xhtml:t.method==="xhtml"}).serialize(o)}var R=x,v=class o{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 N,this.currentTemplate=e.currentTemplate||null,this.currentMode=e.currentMode??null}clone(e={}){return new o({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,currentTemplate:e.currentTemplate??this.currentTemplate,currentMode:e.currentMode??this.currentMode})}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}},b=class{constructor(e={}){this.xpathEvaluator=new N,this.templates=[],this.keys={},this.globalVariables={},this.globalParameters={},this.outputSettings={method:"xml",version:"1.0",encoding:"UTF-8",standalone:null,indent:"no",omitXmlDeclaration:"no",doctypePublic:null,doctypeSystem:null,mediaType:null,cdataSectionElements:[]},this.namespaces={},this.decimalFormats={},this.stylesheetDoc=null,this.attributeSets={},this.namespaceAliases=new X,this.stripSpace=[],this.preserveSpace=[],this.stylesheetLoader=e.stylesheetLoader||null,this.currentImportPrecedence=0,this.processedStylesheets=new Set,this.baseUri=e.baseUri||"",this.documentLoader=e.documentLoader||null,this.loadedDocuments=new Map,this.generatedIds=new WeakMap,this.generatedIdCount=0,this.rootContext=null,this.keyRegistry=new O({keys:this.keys,matchesPattern:(t,r)=>this.matchesPattern(t,r,this.rootContext),evaluateUse:(t,r)=>this.evaluateKeyValues(t,r)}),this.xpathEvaluator.registerFunctions(te(this))}setDocumentLoader(e){return this.documentLoader=e??null,this.loadedDocuments.clear(),this}loadDocument(e,t){let r=se(e);if(r==="")return this.stylesheetDoc;if(!this.documentLoader)return null;let s=z(r,t);if(this.loadedDocuments.has(s))return this.loadedDocuments.get(s);let n=this.documentLoader(s,t),i=typeof n=="string"?this.parseXmlString(n):n||null;return this.loadedDocuments.set(s,i),i}generateId(e){let t=this.generatedIds.get(e);return t||(this.generatedIdCount++,t=`N${this.generatedIdCount}`,this.generatedIds.set(e,t)),t}evaluateKeyValues(e,t){let r=this.rootContext.clone({currentNode:e,currentNodeList:[e],position:1}),s=this.evaluateXPath(t,r);return Array.isArray(s)?s.map(n=>this.xpathEvaluator.getStringValue(n)):[this.xpathEvaluator.toString(s)]}setStylesheetLoader(e){this.stylesheetLoader=e}resolveUri(e,t){return z(e,t)}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 r=this.resolveUri(e,t);return{document:this.stylesheetLoader(r,t),uri:r}}parseXmlString(e){if(typeof DOMParser<"u"){let r=new DOMParser().parseFromString(e,"application/xml"),s=r.querySelector("parsererror");if(s)throw new Error(`XML parse error: ${s.textContent}`);return r}throw new Error("XML parsing not available in this environment")}importStylesheet(e,t){let r=this.stylesheetDoc===null;r&&(this.stylesheetDoc=e.ownerDocument||e,t&&(this.baseUri=t,this.processedStylesheets.add(t)));let s=e.documentElement||e;if(!this.isXsltElement(s,"stylesheet")&&!this.isXsltElement(s,"transform")){if(s.getAttribute&&s.getAttribute("xsl:version")){this.processLiteralResultStylesheet(s);return}throw new Error("Invalid XSLT stylesheet: root element must be xsl:stylesheet or xsl:transform")}this.collectNamespaces(s);let n=[],i=[];for(let a of s.childNodes)a.nodeType===1&&(this.isXsltElement(a,"import")?n.push(a):i.push(a));for(let a of n)this.processImport(a,t||this.baseUri);for(let a of i)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);r&&this.currentImportPrecedence++}processInclude(e,t){let r=e.getAttribute("href");if(!r)throw new Error("xsl:include requires an href attribute");let s=this.resolveUri(r,t);if(this.processedStylesheets.has(s))throw new Error(`Circular stylesheet reference detected: ${s}`);this.processedStylesheets.add(s);try{let{document:n}=this.loadStylesheet(r,t),i=n;typeof n=="string"&&(i=this.parseXmlString(n));let a=this.currentImportPrecedence;this.processIncludedStylesheet(i,s),this.currentImportPrecedence=a}catch(n){throw new Error(`Failed to include stylesheet "${r}": ${n.message}`,{cause:n})}}processImport(e,t){let r=e.getAttribute("href");if(!r)throw new Error("xsl:import requires an href attribute");let s=this.resolveUri(r,t);if(this.processedStylesheets.has(s))throw new Error(`Circular stylesheet reference detected: ${s}`);this.processedStylesheets.add(s);try{let{document:n}=this.loadStylesheet(r,t),i=n;typeof n=="string"&&(i=this.parseXmlString(n)),this.processIncludedStylesheet(i,s),this.currentImportPrecedence++}catch(n){throw new Error(`Failed to import stylesheet "${r}": ${n.message}`,{cause:n})}}processIncludedStylesheet(e,t){let r=e.documentElement||e;if(!this.isXsltElement(r,"stylesheet")&&!this.isXsltElement(r,"transform"))throw new Error("Included/imported document is not a valid XSLT stylesheet");this.collectNamespaces(r);let s=[],n=[];for(let i of r.childNodes)i.nodeType===1&&(this.isXsltElement(i,"import")?s.push(i):n.push(i));for(let i of s)this.processImport(i,t);for(let i of n)this.isXsltElement(i,"template")?this.registerTemplate(i):this.isXsltElement(i,"output")?this.processOutput(i):this.isXsltElement(i,"variable")?this.processGlobalVariable(i):this.isXsltElement(i,"param")?this.processGlobalParam(i):this.isXsltElement(i,"key")?this.processKey(i):this.isXsltElement(i,"decimal-format")?this.processDecimalFormat(i):this.isXsltElement(i,"namespace-alias")?this.processNamespaceAlias(i):this.isXsltElement(i,"attribute-set")?this.processAttributeSet(i):this.isXsltElement(i,"strip-space")?this.processStripSpace(i):this.isXsltElement(i,"preserve-space")?this.processPreserveSpace(i):this.isXsltElement(i,"include")&&this.processInclude(i,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 r=t.name.substring(6);t.value!==R&&(this.namespaces[r]=t.value)}else t.name==="xmlns"&&t.value!==R&&(this.namespaces[""]=t.value)}registerTemplate(e){let t=e.getAttribute("match"),r=e.getAttribute("name"),s=e.getAttribute("mode")||null,n=e.getAttribute("priority"),i=t?this.splitUnionPattern(t).map(a=>a.trim()):[null];for(let a of i)this.templates.push({match:a,name:r,mode:s,priority:n?parseFloat(n):this.calculatePriority(a),importPrecedence:this.currentImportPrecedence,node:e})}calculatePriority(e){return _e(e&&e.trim())}processOutput(e){let t=e.getAttribute("method");t&&(this.outputSettings.method=t);let r=e.getAttribute("version");r&&(this.outputSettings.version=r);let s=e.getAttribute("encoding");s&&(this.outputSettings.encoding=s);let n=e.getAttribute("standalone");n&&(this.outputSettings.standalone=n);let i=e.getAttribute("indent");i&&(this.outputSettings.indent=i);let a=e.getAttribute("omit-xml-declaration");a&&(this.outputSettings.omitXmlDeclaration=a);let l=e.getAttribute("doctype-public");l&&(this.outputSettings.doctypePublic=l);let u=e.getAttribute("doctype-system");u&&(this.outputSettings.doctypeSystem=u);let h=e.getAttribute("media-type");h&&(this.outputSettings.mediaType=h);let f=e.getAttribute("cdata-section-elements");f&&(this.outputSettings.cdataSectionElements=f.split(/\s+/).filter(Boolean))}processGlobalVariable(e){let t=e.getAttribute("name"),r=e.getAttribute("select");this.globalVariables[t]={node:e,select:r}}processGlobalParam(e){let t=e.getAttribute("name"),r=e.getAttribute("select"),s=this.globalParameters[t],n={node:e,select:r};s&&"value"in s&&(n.value=s.value),this.globalParameters[t]=n}setParameterValue(e,t){let r=this.globalParameters[e];r?r.value=t:this.globalParameters[e]={value:t}}clearParameterValue(e){let t=this.globalParameters[e];t&&(t.node?delete t.value:delete this.globalParameters[e])}clearParameterValues(){for(let e of Object.keys(this.globalParameters))this.clearParameterValue(e)}processKey(e){let t=e.getAttribute("name"),r=e.getAttribute("match"),s=e.getAttribute("use");this.keys[t]={match:r,use:s},this.keyRegistry.clear()}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){this.namespaceAliases.add(e)}processAttributeSet(e){let t=e.getAttribute("name"),r=e.getAttribute("use-attribute-sets");this.attributeSets[t]={node:e,useAttributeSets:r?r.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 r=t||(typeof document<"u"?document:null);if(!r)throw new Error("No output document available");let s=Y(r),n=this.prepareSource(e,r),i=new v({currentNode:n,currentNodeList:[n],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});this.rootContext=i;for(let[l,u]of Object.entries(this.globalParameters))l in i.parameters||(i.parameters[l]=this.evaluateVariable(u,i));for(let[l,u]of Object.entries(this.globalVariables))i.variables[l]=this.evaluateVariable(u,i);let a=s.createDocumentFragment();return this.applyTemplates([n],null,i,a),ce(a,r)}prepareSource(e,t){let r=new I(this.stripSpace,this.preserveSpace);return r.isActive()?ie(e,r,Y(t)):e}transformToDocument(e){let t=this.createDocument(e),r=this.transform(e,t);for(;r.firstChild;)t.appendChild(r.firstChild);return t}transformToString(e){let t=this.transform(e,this.createDocument(e));return U(t,this.outputSettings)}createDocument(e){if(typeof document<"u")return document.implementation.createDocument(null,null,null);let t=e&&(e.nodeType===9?e:e.ownerDocument);if(t?.implementation)return t.implementation.createDocument(null,null,null);throw new Error("Document creation not available in this environment")}evaluateVariable(e,t){if("value"in e)return e.value;if(e.select)return this.evaluateXPath(e.select,t);let r=t.outputDocument.createDocumentFragment();return this.processChildren(e.node,t,r),r}applyTemplates(e,t,r,s){let n=Array.isArray(e)?e:[e];for(let i=0;i<n.length;i++){let a=n[i],l=this.findMatchingTemplate(a,t,r);if(l){let u=r.clone({currentNode:a,currentNodeList:n,position:i+1,currentTemplate:l,currentMode:t});this.processTemplate(l.node,u,s)}else this.applyBuiltinTemplate(a,t,r,s)}}findMatchingTemplate(e,t,r,s=1/0){let n=null,i=-1/0,a=-1/0;for(let l of this.templates)if(l.mode===t&&l.match&&!((l.importPrecedence||0)>=s)&&this.matchesPattern(e,l.match,r)){let u=l.priority,h=l.importPrecedence||0;(h>a||h===a&&u>i)&&(n=l,i=u,a=h)}return n}matchesPattern(e,t,r){let s=this.splitUnionPattern(t);for(let n of s)if(this.matchesSinglePattern(e,n.trim(),r))return!0;return!1}splitUnionPattern(e){let t=[],r="",s=0,n=!1,i="";for(let a=0;a<e.length;a++){let l=e[a];n?(r+=l,l===i&&(n=!1)):l==='"'||l==="'"?(n=!0,i=l,r+=l):l==="["?(s++,r+=l):l==="]"?(s--,r+=l):l==="|"&&s===0?(t.push(r),r=""):r+=l}return r&&t.push(r),t}matchesSinglePattern(e,t,r){try{if(t==="/")return e.nodeType===9||e===e.ownerDocument?.documentElement;let s=S(t);if(t.startsWith("/")){let u=e.ownerDocument||e,h=new T(u,1,1,{...r.variables,...r.parameters},r.namespaces,r),f=this.xpathEvaluator.evaluate(s,h);return(Array.isArray(f)?f:[f]).includes(e)}let n=e.nodeType===2?e.ownerElement:e.parentNode;if(n){let u=new T(n,1,1,{...r.variables,...r.parameters},r.namespaces,r),h=this.xpathEvaluator.evaluate(s,u);return(Array.isArray(h)?h:[h]).includes(e)}let i=new T(e,1,1,{...r.variables,...r.parameters},r.namespaces,r),a=this.xpathEvaluator.evaluate(s,i);return(Array.isArray(a)?a:[a]).includes(e)}catch{return!1}}applyBuiltinTemplate(e,t,r,s){switch(e.nodeType){case 1:case 9:case 11:this.applyTemplates(Array.from(e.childNodes),t,r,s);break;case 3:case 4:{let n=r.outputDocument.createTextNode(e.nodeValue||"");s.appendChild(n);break}case 2:{let n=r.outputDocument.createTextNode(e.nodeValue||"");s.appendChild(n);break}}}processTemplate(e,t,r){let s=t.clone();for(let n of e.childNodes)if(n.nodeType===1&&this.isXsltElement(n,"param")){let i=n.getAttribute("name");i in s.parameters||(s.parameters[i]=this.evaluateVariable({node:n,select:n.getAttribute("select")},s))}this.processChildren(e,s,r)}processChildren(e,t,r){for(let s of e.childNodes)this.processNode(s,t,r)}processNode(e,t,r){switch(e.nodeType){case 1:this.processElement(e,t,r);break;case 3:case 4:{let s=e.nodeValue;if(s&&(s.trim()||this.shouldPreserveSpace(e))){let n=t.outputDocument.createTextNode(s);r.appendChild(n)}break}}}shouldPreserveSpace(e){let t=e.parentNode;for(;t&&t.nodeType===1;){let r=t.getAttribute("xml:space");if(r==="preserve")return!0;if(r==="default")return!1;t=t.parentNode}return!1}processElement(e,t,r){this.isXsltNamespace(e)?this.processXsltElement(e,t,r):this.processLiteralResultElement(e,t,r)}processXsltElement(e,t,r){let s=e.localName||e.nodeName.replace(/^xsl:/,"");switch(s){case"apply-templates":this.xslApplyTemplates(e,t,r);break;case"apply-imports":this.xslApplyImports(e,t,r);break;case"call-template":this.xslCallTemplate(e,t,r);break;case"value-of":this.xslValueOf(e,t,r);break;case"text":this.xslText(e,t,r);break;case"element":this.xslElement(e,t,r);break;case"attribute":this.xslAttribute(e,t,r);break;case"if":this.xslIf(e,t,r);break;case"choose":this.xslChoose(e,t,r);break;case"for-each":this.xslForEach(e,t,r);break;case"copy":this.xslCopy(e,t,r);break;case"copy-of":this.xslCopyOf(e,t,r);break;case"variable":this.xslVariable(e,t,r);break;case"param":break;case"comment":this.xslComment(e,t,r);break;case"processing-instruction":this.xslProcessingInstruction(e,t,r);break;case"number":this.xslNumber(e,t,r);break;case"sort":break;case"with-param":break;case"message":this.xslMessage(e,t,r);break;case"fallback":break;default:console.warn(`Unknown XSLT element: ${s}`)}}processLiteralResultElement(e,t,r){let s=e.localName||e.nodeName,n=this.namespaceAliases.resolve(e.namespaceURI,s),i=n?n.namespaceUri:e.namespaceURI,a=n?n.qname:e.nodeName,l=i&&t.outputDocument.createElementNS?t.outputDocument.createElementNS(i,a):t.outputDocument.createElement(a),u=ae(e,"use-attribute-sets",R);if(u&&this.applyAttributeSets(u,t,l),e.attributes)for(let h of e.attributes){if(!oe(h,R))continue;let f=this.processAttributeValueTemplate(h.value,t),A=this.namespaceAliases.resolve(h.namespaceURI,h.localName||h.name);A?l.setAttributeNS(A.namespaceUri,A.qname,f):l.setAttribute(h.name,f)}this.processChildren(e,t,l),r.appendChild(l)}processAttributeValueTemplate(e,t){if(!e.includes("{"))return e;let r="",s=0;for(;s<e.length;)if(e[s]==="{")if(e[s+1]==="{")r+="{",s+=2;else{let n=1,i=s+1;for(;i<e.length&&n>0;)e[i]==="{"?n++:e[i]==="}"&&n--,i++;let a=e.substring(s+1,i-1),l=this.evaluateXPath(a,t);r+=this.xpathEvaluator.toString(l),s=i}else if(e[s]==="}")if(e[s+1]==="}")r+="}",s+=2;else throw new Error("Unmatched } in attribute value template");else r+=e[s],s++;return r}xslApplyTemplates(e,t,r){let s=e.getAttribute("select")||"node()",n=e.getAttribute("mode")||null,i=this.evaluateXPath(s,t);Array.isArray(i)||(i=i?[i]:[]);let a=[];for(let h of e.childNodes)h.nodeType===1&&this.isXsltElement(h,"sort")&&a.push({select:h.getAttribute("select")||".",order:h.getAttribute("order")||"ascending",dataType:h.getAttribute("data-type")||"text",caseOrder:h.getAttribute("case-order")||"upper-first",lang:h.getAttribute("lang")});a.length>0&&(i=this.sortNodes(i,a,t));let l={};for(let h of e.childNodes)if(h.nodeType===1&&this.isXsltElement(h,"with-param")){let f=h.getAttribute("name"),A=h.getAttribute("select");if(A)l[f]=this.evaluateXPath(A,t);else{let w=t.outputDocument.createDocumentFragment();this.processChildren(h,t,w),l[f]=w}}let u=t.clone({parameters:{...t.parameters,...l}});this.applyTemplates(i,n,u,r)}xslApplyImports(e,t,r){let s=t.currentNode,n=t.currentMode??null,i=t.currentTemplate&&t.currentTemplate.importPrecedence||0,a=this.findMatchingTemplate(s,n,t,i);if(!a){this.applyBuiltinTemplate(s,n,t,r);return}this.processTemplate(a.node,t.clone({currentTemplate:a}),r)}xslCallTemplate(e,t,r){let s=e.getAttribute("name"),n=this.templates.find(l=>l.name===s);if(!n)throw new Error(`Template not found: ${s}`);let i={};for(let l of e.childNodes)if(l.nodeType===1&&this.isXsltElement(l,"with-param")){let u=l.getAttribute("name"),h=l.getAttribute("select");if(h)i[u]=this.evaluateXPath(h,t);else{let f=t.outputDocument.createDocumentFragment();this.processChildren(l,t,f),i[u]=f}}let a=t.clone({parameters:{...t.parameters,...i}});this.processTemplate(n.node,a,r)}xslValueOf(e,t,r){let s=e.getAttribute("select"),n=e.getAttribute("disable-output-escaping")==="yes",i=this.evaluateXPath(s,t),a=this.xpathEvaluator.toString(i);if(a){let l=t.outputDocument.createTextNode(a);n&&(l._disableOutputEscaping=!0),r.appendChild(l)}}xslText(e,t,r){let s=e.getAttribute("disable-output-escaping")==="yes",n="";for(let i of e.childNodes)(i.nodeType===3||i.nodeType===4)&&(n+=i.nodeValue||"");if(n){let i=t.outputDocument.createTextNode(n);s&&(i._disableOutputEscaping=!0),r.appendChild(i)}}xslElement(e,t,r){let s=this.processAttributeValueTemplate(e.getAttribute("name"),t),n=e.getAttribute("namespace"),i=e.getAttribute("use-attribute-sets"),a;if(n){let l=this.processAttributeValueTemplate(n,t);a=t.outputDocument.createElementNS(l,s)}else a=t.outputDocument.createElement(s);i&&this.applyAttributeSets(i,t,a),this.processChildren(e,t,a),r.appendChild(a)}xslAttribute(e,t,r){let s=this.processAttributeValueTemplate(e.getAttribute("name"),t),n=e.getAttribute("namespace"),i=t.outputDocument.createDocumentFragment();this.processChildren(e,t,i);let a="",l=u=>{if(u.nodeType===3||u.nodeType===4)a+=u.nodeValue||"";else if(u.childNodes)for(let h of u.childNodes)l(h)};if(l(i),r.nodeType===1)if(n){let u=this.processAttributeValueTemplate(n,t);r.setAttributeNS(u,s,a)}else r.setAttribute(s,a)}xslIf(e,t,r){let s=e.getAttribute("test"),n=this.evaluateXPath(s,t);this.xpathEvaluator.toBoolean(n)&&this.processChildren(e,t,r)}xslChoose(e,t,r){for(let s of e.childNodes)if(s.nodeType===1){if(this.isXsltElement(s,"when")){let n=s.getAttribute("test"),i=this.evaluateXPath(n,t);if(this.xpathEvaluator.toBoolean(i)){this.processChildren(s,t,r);return}}else if(this.isXsltElement(s,"otherwise")){this.processChildren(s,t,r);return}}}xslForEach(e,t,r){let s=e.getAttribute("select"),n=this.evaluateXPath(s,t);Array.isArray(n)||(n=n?[n]:[]);let i=[];for(let a of e.childNodes)a.nodeType===1&&this.isXsltElement(a,"sort")&&i.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")});i.length>0&&(n=this.sortNodes(n,i,t));for(let a=0;a<n.length;a++){let l=t.clone({currentNode:n[a],currentNodeList:n,position:a+1});this.processChildren(e,l,r)}}xslCopy(e,t,r){let s=t.currentNode,n=e.getAttribute("use-attribute-sets");switch(s.nodeType){case 1:{let i;s.namespaceURI?i=t.outputDocument.createElementNS(s.namespaceURI,s.nodeName):i=t.outputDocument.createElement(s.nodeName),n&&this.applyAttributeSets(n,t,i),this.processChildren(e,t,i),r.appendChild(i);break}case 2:r.nodeType===1&&r.setAttribute(s.name,s.value);break;case 3:case 4:{let i=t.outputDocument.createTextNode(s.nodeValue||"");r.appendChild(i);break}case 7:{let i=t.outputDocument.createProcessingInstruction(s.target,s.data);r.appendChild(i);break}case 8:{let i=t.outputDocument.createComment(s.nodeValue||"");r.appendChild(i);break}case 9:case 11:this.processChildren(e,t,r);break}}xslCopyOf(e,t,r){let s=e.getAttribute("select"),n=this.evaluateXPath(s,t);this.copyToOutput(n,t,r)}copyToOutput(e,t,r){if(Array.isArray(e)){for(let s of e)this.copyToOutput(s,t,r);return}if(e&&e.nodeType){let s=this.deepCloneNode(e,t.outputDocument);r.appendChild(s)}else if(typeof e=="string"||typeof e=="number"||typeof e=="boolean"){let s=t.outputDocument.createTextNode(String(e));r.appendChild(s)}}deepCloneNode(e,t){switch(e.nodeType){case 1:{let r;if(e.namespaceURI&&t.createElementNS?r=t.createElementNS(e.namespaceURI,e.nodeName):r=t.createElement(e.nodeName),e.attributes)for(let s of e.attributes)r.setAttribute(s.name,s.value);for(let s of e.childNodes)r.appendChild(this.deepCloneNode(s,t));return r}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 r=t.createDocumentFragment();for(let s of e.childNodes)r.appendChild(this.deepCloneNode(s,t));return r}default:return t.createTextNode("")}}xslVariable(e,t,r){let s=e.getAttribute("name"),n=e.getAttribute("select"),i;if(n)i=this.evaluateXPath(n,t);else{let a=t.outputDocument.createDocumentFragment();this.processChildren(e,t,a),i=a}t.setVariable(s,i)}xslComment(e,t,r){let s=t.outputDocument.createDocumentFragment();this.processChildren(e,t,s);let n="",i=l=>{if(l.nodeType===3||l.nodeType===4)n+=l.nodeValue||"";else if(l.childNodes)for(let u of l.childNodes)i(u)};i(s);let a=t.outputDocument.createComment(n);r.appendChild(a)}xslProcessingInstruction(e,t,r){let s=this.processAttributeValueTemplate(e.getAttribute("name"),t),n=t.outputDocument.createDocumentFragment();this.processChildren(e,t,n);let i="",a=u=>{if(u.nodeType===3||u.nodeType===4)i+=u.nodeValue||"";else if(u.childNodes)for(let h of u.childNodes)a(h)};a(n);let l=t.outputDocument.createProcessingInstruction(s,i);r.appendChild(l)}xslNumber(e,t,r){let s=e.getAttribute("value"),n=e.getAttribute("format")||"1",i;s?i=[Math.round(this.xpathEvaluator.toNumber(this.evaluateXPath(s,t)))]:i=re(t.currentNode,{level:e.getAttribute("level")||"single",count:e.getAttribute("count"),from:e.getAttribute("from")},(l,u)=>this.matchesPattern(l,u,t));let a=t.outputDocument.createTextNode(B(i,n));r.appendChild(a)}formatNumber(e,t){return B([e],t)}toRoman(e){return C(e)}xslMessage(e,t,r){let s=e.getAttribute("terminate")==="yes",n=t.outputDocument.createDocumentFragment();this.processChildren(e,t,n);let i="",a=l=>{if(l.nodeType===3||l.nodeType===4)i+=l.nodeValue||"";else if(l.childNodes)for(let u of l.childNodes)a(u)};if(a(n),console.log("XSLT Message:",i),s)throw new Error(`XSLT terminated: ${i}`)}applyAttributeSets(e,t,r){let s=e.split(/\s+/).filter(Boolean);for(let n of s){let i=this.attributeSets[n];if(i){i.useAttributeSets.length>0&&this.applyAttributeSets(i.useAttributeSets.join(" "),t,r);for(let a of i.node.childNodes)a.nodeType===1&&this.isXsltElement(a,"attribute")&&this.xslAttribute(a,t,r)}}}sortNodes(e,t,r){return[...e].sort((s,n)=>{for(let i of t){let a=r.clone({currentNode:s}),l=r.clone({currentNode:n}),u=this.evaluateXPath(i.select,a),h=this.evaluateXPath(i.select,l);u=this.xpathEvaluator.toString(u)||"",h=this.xpathEvaluator.toString(h)||"",i.dataType==="number"?(u=parseFloat(u)||0,h=parseFloat(h)||0):i.caseOrder==="lower-first"?(u=u.toLowerCase(),h=h.toLowerCase()):(u=u.toUpperCase(),h=h.toUpperCase());let f;if(typeof u=="number"?f=u-h:f=u.localeCompare(h,i.lang||void 0),i.order==="descending"&&(f=-f),f!==0)return f}return 0})}evaluateXPath(e,t){let r=S(e),s=new T(t.currentNode,t.position,t.currentNodeList.length,{...t.variables,...t.parameters},t.namespaces,t);return this.xpathEvaluator.evaluate(r,s)}isXsltNamespace(e){return e.namespaceURI===R||e.nodeName&&e.nodeName.startsWith("xsl:")}isXsltElement(e,t){if(e.nodeType!==1)return!1;let r=e.localName||e.nodeName;return e.namespaceURI===R&&r===t||e.nodeName===`xsl:${t}`}};var _=class{constructor(){this._engine=null,this._stylesheet=null,this._parameters=new Map,this._stylesheetLoader=null,this._documentLoader=null}get engine(){return this._engine}setStylesheetLoader(e){if(e!=null&&typeof e!="function")throw new TypeError("Failed to execute 'setStylesheetLoader' on 'XSLTProcessor': The loader argument must be a function or null.");return this._stylesheetLoader=e??null,this._engine&&this._engine.setStylesheetLoader(this._stylesheetLoader),this}setDocumentLoader(e){if(e!=null&&typeof e!="function")throw new TypeError("Failed to execute 'setDocumentLoader' on 'XSLTProcessor': The loader argument must be a function or null.");return this._documentLoader=e??null,this._engine&&this._engine.setDocumentLoader(this._documentLoader),this}importStylesheet(e,t){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 b({stylesheetLoader:this._stylesheetLoader,documentLoader:this._documentLoader});for(let[s,n]of this._parameters)this._engine.setParameterValue(s,n);this._engine.importStylesheet(e,t)}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(r){return console.error("XSLT transformation error:",r),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}}transformToString(e){if(!e)throw new TypeError("Failed to execute 'transformToString' on 'XSLTProcessor': 1 argument required, but only 0 present.");if(!this._engine||!this._stylesheet)throw new Error("Failed to execute 'transformToString' on 'XSLTProcessor': No stylesheet has been imported.");if(e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)throw new TypeError("Failed to execute 'transformToString' on 'XSLTProcessor': The source is not a valid node type.");try{return this._engine.transformToString(e)}catch(t){return console.error("XSLT transformation error:",t),null}}setParameter(e,t,r){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 s=e?`{${e}}${t}`:t;this._parameters.set(s,r),this._engine&&this._engine.setParameterValue(s,r)}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 r=e?`{${e}}${t}`:t;return this._parameters.has(r)?this._parameters.get(r):""}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 r=e?`{${e}}${t}`:t;this._parameters.delete(r),this._engine&&this._engine.clearParameterValue(r)}clearParameters(){this._parameters.clear(),this._engine&&this._engine.clearParameterValues()}reset(){this._engine=null,this._stylesheet=null,this._parameters.clear()}};function me(){if(typeof globalThis.XSLTProcessor>"u")return!1;try{let o=new globalThis.XSLTProcessor,e=new DOMParser,t=e.parseFromString(`<?xml version="1.0"?>
2
6
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3
7
  <xsl:template match="/"><test/></xsl:template>
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);})();
8
+ </xsl:stylesheet>`,"application/xml");o.importStylesheet(t);let r=e.parseFromString("<root/>","application/xml"),s=o.transformToFragment(r,document);return s!==null&&s.childNodes.length>0}catch{return!1}}function He(o=!1){return!o&&me()?!1:(globalThis.XSLTProcessor=_,!0)}var We=_;function fe(o,e,t={}){let r=S(o),s=new N,n=new T(e,1,1,t.variables||{},t.namespaces||{});return s.evaluate(r,n)}function de(o,e,t={}){let r=fe(o,e,t);return Array.isArray(r)?r:r&&r.nodeType?[r]:[]}function Ge(o,e,t={}){let r=de(o,e,t);return r.length>0?r[0]:null}var kt="1.1.1",Mt=typeof window<"u"&&typeof document<"u",Ut=typeof process<"u"&&process.versions?.node!=null;return Je(Ft);})();
5
9
  if(typeof window!=='undefined'){XsltProcessorLib.installGlobal();}
6
10
  //# sourceMappingURL=xslt-processor.browser.min.js.map