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

Incorrect output for Mozilla example #110

Open
erickoledadevrel opened this issue Oct 18, 2024 · 1 comment
Open

Incorrect output for Mozilla example #110

erickoledadevrel opened this issue Oct 18, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@erickoledadevrel
Copy link

When testing this library I used a sample XML + XSLT from the Mozilla website. The library doesn't seem to work correctly with this example, although I haven't been able to determine why exactly.

Repro

  1. Install the library.
  2. Run the following code (Node.js).
const xslt = require('xslt-processor');

const xmlString = `
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="example.xsl"?>
<Article>
  <Title>My Article</Title>
  <Authors>
    <Author>Mr. Foo</Author>
    <Author>Mr. Bar</Author>
  </Authors>
  <Body>This is my article text.</Body>
</Article>
`;

const xsltString = `
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="text"/>

  <xsl:template match="/">
    Article - <xsl:value-of select="/Article/Title"/>
    Authors: <xsl:apply-templates select="/Article/Authors/Author"/>
  </xsl:template>

  <xsl:template match="Author">
    - <xsl:value-of select="." />
  </xsl:template>

</xsl:stylesheet>
`;

const processor = new xslt.Xslt();
const parser = new xslt.XmlParser();
const result = processor.xsltProcess(
  parser.xmlParse(xmlString),
  parser.xmlParse(xsltString)
).then(result => console.log(result));

Expected


    Article - My Article
    Authors: 
    - Mr. Foo
    - Mr. Bar

Actual


    - My ArticleMr. FooMr. Bar
@leonelsanchesdasilva leonelsanchesdasilva self-assigned this Oct 18, 2024
@leonelsanchesdasilva leonelsanchesdasilva added the bug Something isn't working label Oct 18, 2024
@leonelsanchesdasilva
Copy link
Collaborator

Hi @erickoledadevrel 👋

Thanks for reporting this. I added the corresponding unit test in the codebase.

It's basically what was reported in #108 and #109: the logic handling text nodes is not great, and the problem happens because text nodes are overridden when they should not.

As I mentioned in the other issues, there are two problems to be solved here:

I started thinking about the logic on this some time ago, but I didn't have the time to dedicate myself to this. I hope to get some time in the next weeks to plan a good algorithm and implement it. Your example should help me tremendously on it.

leonelsanchesdasilva added a commit that referenced this issue Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants