ricksbrown / xslmin

An XSLT minifier
4 stars 0 forks source link

Cannot minify XSLTFORMS.xsl #3

Open ricksbrown opened 10 years ago

ricksbrown commented 10 years ago

From here: https://code.google.com/p/xslmin/issues/detail?id=5

Reported by jbejar86, May 8, 2012 What steps will reproduce the problem?

  1. Download the Beta 3 version of XSLTForms.xsl http://xsltforms.svn.sourceforge.net/viewvc/xsltforms/releases/beta3/
  2. Run xslmin-1.2 or 2.2 and they both fail, except 2.2 crashes
  3. 1.2 doesn't render my XForms correctly

What is the expected output? What do you see instead? On 2.2 I see C:\Users\jbejar\Downloads>java -jar xslmin-2.2.jar xsltforms.xsl out.xsl Begining minification, input xsltforms.xsl output: out.xsl Preserve is OFF - unused elements will be removed. java.lang.IllegalStateException: The node should not be re-set at com.googlecode.monkeybrown.xslmin.NamedNode.setNode(NamedNode.java:91 ) at com.googlecode.monkeybrown.xslmin.Scope.addScoped(Scope.java:143) at com.googlecode.monkeybrown.xslmin.Scope.addScoped(Scope.java:156) at com.googlecode.monkeybrown.xslmin.Scope.addScoped(Scope.java:161) at com.googlecode.monkeybrown.xslmin.Stylesheet.walkLevel(Stylesheet.jav a:345) at com.googlecode.monkeybrown.xslmin.Stylesheet.walkLevel(Stylesheet.jav a:373) at com.googlecode.monkeybrown.xslmin.Stylesheet.walkLevel(Stylesheet.jav a:373) at com.googlecode.monkeybrown.xslmin.Stylesheet.walkLevel(Stylesheet.jav a:373) at com.googlecode.monkeybrown.xslmin.Stylesheet.walkLevel(Stylesheet.jav a:373) at com.googlecode.monkeybrown.xslmin.Stylesheet.walkLevel(Stylesheet.jav a:369) at com.googlecode.monkeybrown.xslmin.Stylesheet.walkLevel(Stylesheet.jav a:373) at com.googlecode.monkeybrown.xslmin.Stylesheet.(Stylesheet.java:5 3) at com.googlecode.monkeybrown.xslmin.XslMin.minify(XslMin.java:75) at com.googlecode.monkeybrown.xslmin.XslMin.main(XslMin.java:47)

C:\Users\jbejar\Downloads>

What version of the product are you using? On what operating system? both, Windows 7

Please provide any additional information below.

xsltforms.xsl 

150 KB Download

Sep 9, 2012 Delete comment Project Member #1 ricksbrown73 Hi, thanks for reporting this issue and sorry about the delay in responding.

I am easily able to replicate this issue and can confirm that the XSL minfier does crash and should probably be a little more polite in the way it handles this scenario. Thanks for the good defect report.

The problem is caused by the fact that your XSLT defines the same variable repeatedly in the same template - I never tested this because it is actually not legit and is actually highlighting some potential bugs in your XSLT.

For example on line 145 and line 167 of the attached xsltforms.xsl your xslt defines the variable "nstype" in the same template. That is not legit.

Incidentally the variable is being assigned to in a for loop. That is also a potential bug - variables in XSLT are immutable - only the first assignment will work, after that each assignment in the for loop will do nothing - perhaps that's what the author intended but it is a little odd.

My intention is to fix this so that it handles this situation more politely than simply crashing. Status: Accepted Owner: ricksbrown73 Sep 9, 2012 Delete comment Project Member #2 ricksbrown73 Issue 4 has been merged into this issue.

AirQuick commented 9 years ago

Not a good practice, but from the description of xsl:variable in "XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition",

To take an extreme example, it is legal to write:

<xsl:variable name="x" select="'A'"/>

<xsl:template match="para">
  <xsl:variable name="x" select="$x, 'B'"/>
  <xsl:variable name="x" select="$x, 'C'"/>
  <xsl:value-of select="for $x in ($x, 'D') return ($x, '+')"/>
</xsl:template>