Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can the jwL:compileGrammar be improved to convert its input to a string if an input node with a grammar is passed in? #2

Open
martin-honnen opened this issue Jul 25, 2022 · 2 comments

Comments

@martin-honnen
Copy link

Hi John,

I have started to try to integrate your Invisible XML library in my XSLT 3, SaxonJS based fidde at https://martin-honnen.github.io/xslt3fiddle/index-iXML.html. I hope I have understood the documentation and comments in the code fine, I have run into one oddity where I wonder whether your function signature or the type checking in the function can be improved.

Sometimes I expect the input XML of the XSLT transformation to contain a grammar to be parsed in some XML element e.g. in a sample I have

<?xml version="1.0" encoding="utf-8"?>
<html lang="en">
  <head>
    <title>Saxon-JS 2.4 XSLT 3 and iXML fiddle</title>
  </head>
  <body>
    <section>
      <h1>jwiXML Test</h1>
      <section>
        <h3>Invisible XML example</h3>
        <section>
          <h4>Grammar</h4>
          <pre><code id="grammar1">Countries = Country*.
Country = Name, -'/', Code, -'/', Line, #A?.
Name = ['A'-'Z'],['A'-'Z'].
Code = ['0'-'9'],['0'-'9'],['0'-'9'].
Line = ['0'-'9'],['0'-'9'].</code>
          </pre>
          <h4>Sample data</h4>
          <pre><code id="data">UK/006/10
US/004/12</code></pre>
        </section>
      </section>
    </section>
  </body>
</html>

and then it "only" works fine to pass the string value of that code id="grammar1" element to the jwL:compileGrammar function, i.e. doing

    <xsl:sequence
      select="jwL:parse(jwL:compileGrammar(//code[@id = 'grammar1']/string()), //code[@id = 'data'])?tree"/>

works fine, however simply passing the element node, as in

  <xsl:sequence
     select="jwL:parse(jwL:compileGrammar(//code[@id = 'grammar1']), //code[@id = 'data'])?tree"/>

gives me an error Failed to call method function(a){a instanceof Document?(a=Cb(a),a.compile()):(a=(new Db).parse(a),a.compile());return a}.

Is that expected? I am afraid I am not able to infer what the minimized Cb(a) or (new Db).parse(a) are supposed to do or what kind of input they take.

So I need your help to tell me whether the explicit string conversion I needed to do is a wanted requirement or whether you can improve the function/API to do that automagically.

Full examples are: failure , success.

@johnlumley
Copy link
Owner

johnlumley commented Jul 25, 2022 via email

@martin-honnen
Copy link
Author

Thanks, @johnlumle, with your update the test now works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants