-
-
Notifications
You must be signed in to change notification settings - Fork 903
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
Avoid incorrectly including xml header in xslt output on JRuby #2903
base: main
Are you sure you want to change the base?
Avoid incorrectly including xml header in xslt output on JRuby #2903
Conversation
Html is not obviously the correct method when none is specified. If this is the correct default, I think you should add a comment explaining why it's correct. |
E.g., does this make the jruby implementation match the C implementation? (I'm on my phone so I cannot easily check.) |
After digging into this a bit, I don't think this is the correct fix. The XSLT standard specifies how the default method should be determined—either XML or HTML—when none is specified by the stylesheet. For some reason, this is not being correctly detected by Xalan. (The code that's supposed to do that is here, I think.) If I modify the code in #1430 slightly to call Here's the code. input_xml = <<-EOS
<?xml version="1.0" encoding="utf-8"?>
<report>
<title>My Report</title>
</report>
EOS
input_xsl = <<-EOS
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title><xsl:value-of select="report/title"/></title>
</head>
<body>
<h1><xsl:value-of select="report/title"/></h1>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
EOS
require 'nokogiri'
xml = Nokogiri::XML(input_xml)
xsl = Nokogiri::XSLT(input_xsl)
html = xsl.transform(xml)
puts(html.root.name)
puts(html.root.namespace || "no namespace") |
Thank you for your feedback and for providing additional insights into the issue! Based on your comments, it appears that determining the correct default method (XML or HTML) when it is not explicitly specified can be a complex matter. As you said, it seems that Xalan is not correctly detecting the default method according to the XSLT standard. Considering this, I propose handling the default method determination within the serialize method itself. By doing so, we can ensure that the output format aligns with the expected behavior, especially when the method is not explicitly specified. Like this: |
I'm going to close this, and we can continue the conversation at #1430 |
Oh, apologies, I see you pushed additional changes that are trying to implement what Steve is describing ... reopening |
@cbasguti I appreciate the time and effort you've put into trying to fix this issue. However, I'm not confident that we understand what's going on enough to start working around it by writing our own Java code. If it's a bug in Xalan, we should report it upstream and/or submit a patch there. If it's not a bug in Xalan, then it may be that we're using the library incorrectly and so the fix to Nokogiri should then be a usage fix to how we're calling the libraries. I'll leave this open for now, but let's continue the conversation in #1430. |
What problem is this PR intended to solve?
Have you included adequate test coverage?
A new test file named test_xml_header.rb was added .
Does this change affect the behavior of either the C or the Java implementations?
The modification made to the Java implementation was to exclude the XML declaration tag () from the output. This was achieved by adjusting the code in the serialize function to remove the inclusion of the XML declaration. The purpose was to align the output with the expected format, where the XML declaration should not be present.