diff --git a/src/xslt/xslt.ts b/src/xslt/xslt.ts index 06ea145..33a16c0 100644 --- a/src/xslt/xslt.ts +++ b/src/xslt/xslt.ts @@ -291,13 +291,13 @@ export class Xslt { this.xsltWithParam(paramContext, template); for (let i = 0; i < top.childNodes.length; ++i) { - let c = top.childNodes[i]; + let childNode = top.childNodes[i]; if ( - c.nodeType == DOM_ELEMENT_NODE && - this.isXsltElement(c, 'template') && - domGetAttributeValue(c, 'name') == name + childNode.nodeType === DOM_ELEMENT_NODE && + this.isXsltElement(childNode, 'template') && + domGetAttributeValue(childNode, 'name') == name ) { - this.xsltChildNodes(paramContext, c, output); + this.xsltChildNodes(paramContext, childNode, output); break; } } @@ -478,13 +478,13 @@ export class Xslt { } /** - * Implements xsl:choose and its child nodes xsl:when and - * xsl:otherwise. - * @param input The Expression Context. + * Implements `xsl:choose`, its child nodes `xsl:when`, and + * `xsl:otherwise`. + * @param context The Expression Context. * @param template The template. * @param output The output. */ - protected xsltChoose(input: ExprContext, template: any, output: any) { + protected xsltChoose(context: ExprContext, template: XNode, output: any) { for (const childNode of template.childNodes) { if (childNode.nodeType !== DOM_ELEMENT_NODE) { continue; @@ -492,12 +492,12 @@ export class Xslt { if (this.isXsltElement(childNode, 'when')) { const test = xmlGetAttribute(childNode, 'test'); - if (this.xPath.xPathEval(test, input).booleanValue()) { - this.xsltChildNodes(input, childNode, output); + if (this.xPath.xPathEval(test, context).booleanValue()) { + this.xsltChildNodes(context, childNode, output); break; } } else if (this.isXsltElement(childNode, 'otherwise')) { - this.xsltChildNodes(input, childNode, output); + this.xsltChildNodes(context, childNode, output); break; } } @@ -662,14 +662,14 @@ export class Xslt { * Evaluates a variable or parameter and set it in the current input * context. Implements `xsl:variable`, `xsl:param`, and `xsl:with-param`. * - * @param input TODO - * @param template TODO + * @param context The expression context. + * @param template The template node. * @param override flag that defines if the value computed here * overrides the one already in the input context if that is the * case. I.e. decides if this is a default value or a local * value. `xsl:variable` and `xsl:with-param` override; `xsl:param` doesn't. */ - protected xsltVariable(input: ExprContext, template: any, override: boolean) { + protected xsltVariable(context: ExprContext, template: XNode, override: boolean) { const name = xmlGetAttribute(template, 'name'); const select = xmlGetAttribute(template, 'select'); @@ -677,10 +677,12 @@ export class Xslt { if (template.childNodes.length > 0) { const root = domCreateDocumentFragment(template.ownerDocument); - this.xsltChildNodes(input, template, root); + this.xsltChildNodes(context, template, root); value = new NodeSetValue([root]); } else if (select) { - value = this.xPath.xPathEval(select, input); + value = this.xPath.xPathEval(select, context); + } else if (name in context.variables) { + value = context.variables[name]; } else { let parameterValue = ''; const filteredParameter = this.options.parameters.filter((p) => p.name === name); @@ -690,8 +692,8 @@ export class Xslt { value = new StringValue(parameterValue); } - if (override || !input.getVariable(name)) { - input.setVariable(name, value); + if (override || !context.getVariable(name)) { + context.setVariable(name, value); } } @@ -892,13 +894,13 @@ export class Xslt { * current template node, in the current input context. This happens * before the operation specified by the current template node is * executed. - * @param input TODO - * @param template TODO + * @param context The Expression Context. + * @param template The template node. */ - protected xsltWithParam(input: ExprContext, template: any) { - for (const c of template.childNodes) { - if (c.nodeType === DOM_ELEMENT_NODE && this.isXsltElement(c, 'with-param')) { - this.xsltVariable(input, c, true); + protected xsltWithParam(context: ExprContext, template: XNode) { + for (const childNode of template.childNodes) { + if (childNode.nodeType === DOM_ELEMENT_NODE && this.isXsltElement(childNode, 'with-param')) { + this.xsltVariable(context, childNode, true); } } } diff --git a/tests/lmht/lmht.test.tsx b/tests/lmht/lmht.test.tsx index 6846ac3..449ecee 100644 --- a/tests/lmht/lmht.test.tsx +++ b/tests/lmht/lmht.test.tsx @@ -10,1523 +10,1566 @@ import { XmlParser } from '../../src/dom'; console.log(dom); describe('LMHT', () => { const xsltString = - '' + - ( - - + '' + + ( + + - - - - _self - _blank - _parent - _top - - - - - - default - rect - circle - poly - - - - - - - unsafe-url - - same-origin - origin - - origin-when-cross-origin - - - strict-origin-when-cross-origin - - no-referrer - - no-referrer-when-downgrade - - - - - - - auto - metadata - circle - - - - - - help - alternate - prev - author - external - - license - - bookmark - - nofollow - - tag - search - next - noreferrer - noopener - - + + + + _self + _blank + _parent + _top + + + + + + default + rect + circle + poly + + + + + + + unsafe-url + + same-origin + origin + origin-when-cross-origin + + strict-origin-when-cross-origin + + no-referrer + + no-referrer-when-downgrade + + + + + + + auto + metadata + circle + + + + + + help + alternate + prev + author + external + license + bookmark + + nofollow + + tag + search + next + noreferrer + noopener + + + + + + button + checkbox + color + date + email + file + hidden + image + month + number + password + radio + range + reset + search + submit + tel + text + time + week + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <xsl:apply-templates select="@*|node()" /> - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <xsl:apply-templates select="@*|node()" /> + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
-
- - - - - - -
- -
-
- -
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
-
- -
- -
-
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ +
+
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
- -
- -
-
- -
- -
-
- -
- -
-
- -
    - -
-
- - - - - - - - - -
    - -
-
- -
  • - -
  • -
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
      + +
    +
    + + + + + + + + + +
      + +
    +
    + +
  • + +
  • +
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    - -

    -
    - -
    -                            
    -                        
    -
    - -
    - -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - -
    -
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

    + +

    +
    + +
    +                        
    +                    
    +
    + +
    + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +
    +
    + + + + +
    + +
    +
    - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - -

    - -

    -
    - -

    - -

    -
    - -

    - -

    -
    - -

    - -

    -
    - -
    - -
    -
    - -
    - -
    -
    - - - - - - - - -
    - ); + +

    + +

    +
    + +

    + +

    +
    + +

    + +

    +
    + +

    + +

    +
    + +
    + +
    +
    + +
    + +
    +
    + + + + + + + + +
    + ); it('Trivial', () => { const xmlString = ( @@ -1576,21 +1619,22 @@ describe('LMHT', () => { ); - const expectedOutString = ``+ - ``+ - ``+ - ``+ - ``+ - ``+ - `Meu blog`+ - ``+ - ``+ - ``+ - `
    `+ - `

    Meu primeiro artigo

    `+ - `

    Este é meu primeiro artigo.

    `+ - `
    `+ - ``+ + const expectedOutString = + `` + + `` + + `` + + `` + + `` + + `` + + `Meu blog` + + `` + + `` + + `` + + `
    ` + + `

    Meu primeiro artigo

    ` + + `

    Este é meu primeiro artigo.

    ` + + `
    ` + + `` + ``; const xsltClass = new Xslt({ selfClosingTags: false }); @@ -1615,21 +1659,26 @@ describe('LMHT', () => { it('Form Fieldset', () => { const xmlString = ` - Teste - - Detalhes de Artigo - - - id - - titulo - - conteudo - - - - - `; + Editar Artigo + + Editar Artigo + + + + id + + titulo + + conteudo + + + + + + + + + `; const xsltClass = new Xslt({ selfClosingTags: false }); const xmlParser = new XmlParser(); const xml = xmlParser.xmlParse(xmlString); @@ -1637,5 +1686,5 @@ describe('LMHT', () => { const outXmlString = xsltClass.xsltProcess(xml, xslt); assert.ok(outXmlString); - }) + }); });