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

[help] XSLT::Stylesheet#transform return infinite template recursion error #3321

Open
ChrisKaun opened this issue Nov 7, 2024 · 1 comment

Comments

@ChrisKaun
Copy link

What problem are you trying to solve?

I try to transform the zugferd/factur-x schema file with the xslt2 into a schematron to be able to validate incoming factur-x xml invoices.

Please show your code!

Here is a zip file with the schema file and the iso-schematron-xslt2 files:
files.zip

The 'iso_dsdl_include.xsl' file will raise an error when tranforming.
Example code:

require 'nokogiri'

schema_path = File.join(__dir__, 'Factur-X_1.0.07_EN16931.sch')
schematron_doc = Nokogiri::XML(File.read(schema_path))
xsl_path = File.join(__dir__, 'iso_dsdl_include.xsl')
xsl_file = Nokogiri::XSLT(File.read(xsl_path))
xsl_file.transform(schematron_doc)

=> (irb):7:in `transform': runtime error: element value-of (RuntimeError)
xsltApplySequenceConstructor: A potential infinite template recursion was detected.

FullError:

(irb):7:in `transform': runtime error: element value-of (RuntimeError)
xsltApplySequenceConstructor: A potential infinite template recursion was detected.
You can adjust xsltMaxDepth (--maxdepth) in order to raise the maximum number of nested template calls and variables/params (currently set to 3000).
Templates:
#0 name strip-strings
#1 name strip-strings
#2 name strip-strings
#3 name strip-strings
#4 name strip-strings
#5 name strip-strings
#6 name strip-strings
#7 name strip-strings
#8 name strip-strings
#9 name strip-strings
#10 name strip-strings
#11 name strip-strings
#12 name strip-strings
#13 name strip-strings
#14 name strip-strings
Variables:
#0
mode
string
#1
string
#2
mode
string
#3
string
#4
mode
string
#5
string
#6
mode
string
#7
string
#8
mode
string
#9
string
#10
mode
string
#11
string
#12
mode
string
#13
string
#14
mode
string
        from (irb):7:in `<main>'
        from /home/.../.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
        from /home/.../.rbenv/versions/3.1.2/bin/irb:25:in `load'
        from /home/.../.rbenv/versions/3.1.2/bin/irb:25:in `<top (required)>'
        from /home/.../.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.5.22/lib/bundler/cli/exec.rb:58:in `load'
        from /home/.../.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.5.22/lib/bundler/cli/exec.rb:58:in `kernel_load'
        from /home/.../.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.5.22/lib/bundler/cli/exec.rb:23:in `run'
        from /home/.../.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.5.22/lib/bundler/cli.rb:455:in `exec'
        from /home/.../.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.5.22/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
        from /home/.../.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.5.22/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
        from /home/.../.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.5.22/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
        from /home/.../.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.5.22/lib/bundler/cli.rb:35:in `dispatch'
        from /home/.../.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.5.22/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
        from /home/.../.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.5.22/lib/bundler/cli.rb:29:in `start'
        from /home/.../.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.5.22/exe/bundle:28:in `block in <top (required)>'
        from /home/.../.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.5.22/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
        ... 3 levels...

Environment

  • nokogiri 1.16.7
  • ruby 3.1.2
  • ubuntu 20.04

Additional context
I tried to adapt the codebase of the nokogiri-schematron gem (https://github.com/alexxed/schematron) which wasn't updated in ~8 years.

@flavorjones
Copy link
Member

@ChrisKaun Thanks for asking this question.

Nokogiri doesn't currently support Schematron, although libxml2 itself does. I honestly don't know much about Schematron, and have never used it myself. Can you explain a bit more about what this code snippet is supposed to do? Can you say more about why you aren't using the gem that you mention (it seems like it still passes its test suite with modern Nokogiri)?

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

No branches or pull requests

2 participants