[
https://issues.apache.org/jira/browse/XALANJ-2448?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12603563#action_12603563
]
Henry Zongaro commented on XALANJ-2448:
---------------------------------------
I think there's a bug in your stylesheet. In the template that matches
wf:flow, you have this:
<xsl:template match="wf:flow">
<wf:flow>
<xsl:call-template name="steps">
<xsl:with-param name="compnum" select="'1'"/>
<xsl:with-param name="stepindex" select="'1'"/>
<xsl:with-param name="yoffset" select="'0'"/>
<xsl:with-param name="maxyoffset" select="'0'"/>
</xsl:call-template>
</wf:flow>
</xsl:template>
Note particularly that the value of stepindex is the string literal '1' rather
than the numeric value 1. Then inside the "steps" template you have this:
<xsl:variable name="stepname" select="$comp/wf:step-name[$stepindex]"/>
The value of the $stepindex is a string. According to section 2.4 of XPath,[1]
"A PredicateExpr is evaluated by evaluating the Expr and converting the result
to a boolean. If the result is a number, the result will be converted to true
if the number is equal to the context position and will be converted to false
otherwise; if the result is not a number, then the result will be converted as
if by a call to the boolean function." In this case, the expression has a
string value, which is converted to a boolean by checking its length (see
section 4.3[2]) - the length is greater than zero, so the predicate is true for
all $comp/wf:step-name. That selects all four wf:step-name nodes:
<wf:step-name>Start</wf:step-name>
<wf:step-name>Step-1</wf:step-name>
<wf:step-name>Error</wf:step-name>
<wf:step-name>Success</wf:step-name>
Then you have the following. Here the predicate is true if the name attribute
of a wf:step is equal to the string value of any one of the wf:step-name nodes
in $stepname - that is, for all four wf:step elements.
<xsl:for-each select="/wf:flow/wf:[EMAIL PROTECTED]">
If you change the xsl:with-param for stepindex in the initial xsl:call-template
to the following, passing in a number instead of a string, your stylesheet
should work correctly:
<xsl:with-param name="stepindex" select="1"/>
I hope that helps. If the problem remains, please reopen this bug report.
[1] http://www.w3.org/TR/xpath#predicates
[2] http://www.w3.org/TR/xpath#function-boolean
> Invalid XPath evaulation - got list of nodes instead of 1 node
> --------------------------------------------------------------
>
> Key: XALANJ-2448
> URL: https://issues.apache.org/jira/browse/XALANJ-2448
> Project: XalanJ2
> Issue Type: Bug
> Security Level: No security risk; visible to anyone(Ordinary problems in
> Xalan projects. Anybody can view the issue.)
> Affects Versions: 2.7.1, 2.7, 2.6, 2.5, 2.5Dx, 2.4, 2.4Dx, 2.3, 2.3Dx,
> 2.2.x, 2.2.0, 2.1.0, 2.0.4, 2.0.3, 2.0.2, 2.0.1, 2.0.0, 2.0.x
> Environment: Linux 2.6.23.9-mactel. Java 1.6.0_03 or 1.5.0_15
> Reporter: Vaclav Bartacek
>
> Different results between XALAN and the default Java XLST processor.
> The difference is printed in <xsl:message>COUNT=.....
> The COUNT should be "1", but is actually "4".
> And also the result files out-xalan.xml and out-default.xml differ.
> I suspect problems with recursion.
> -------------------------------------------------------------
> style.xsl:
> <?xml version="1.0" encoding="utf-8"?>
> <xsl:stylesheet
> version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:wf="http://www.emeldi.com/tboss/hot-deploy/workflow"
> >
> <xsl:output
> method="xml"
> indent="yes"
> omit-xml-declaration="no"
> encoding="utf-8"/>
> <xsl:template match="wf:flow">
> <wf:flow>
> <xsl:call-template name="steps">
> <xsl:with-param name="compnum" select="'1'"/>
> <xsl:with-param name="stepindex" select="'1'"/>
> <xsl:with-param name="yoffset" select="'0'"/>
> <xsl:with-param name="maxyoffset" select="'0'"/>
> </xsl:call-template>
> </wf:flow>
> </xsl:template>
> <xsl:template name="steps">
> <xsl:param name="compnum"/>
> <xsl:param name="stepindex"/>
> <xsl:param name="yoffset"/>
> <xsl:param name="maxyoffset"/>
> <xsl:variable name="comp" select="/wf:flow/wf:components/wf:[EMAIL
> PROTECTED]"/>
> <xsl:choose>
> <xsl:when test="$comp">
> <xsl:variable name="stepname" select="$comp/wf:step-name[$stepindex]"/>
> <xsl:choose>
> <xsl:when test="$stepname">
> <xsl:if test="$stepname='Start'">
> <xsl:message>
> COUNT=<xsl:value-of select="count(/wf:flow/wf:[EMAIL PROTECTED])"/>
> </xsl:message>
> </xsl:if>
> <xsl:for-each select="/wf:flow/wf:[EMAIL PROTECTED]">
> <xsl:call-template name="step">
> <xsl:with-param name="compnum" select="$compnum"/>
> <xsl:with-param name="stepindex" select="$stepindex"/>
> <xsl:with-param name="yoffset" select="$yoffset"/>
> <xsl:with-param name="maxyoffset" select="$maxyoffset"/>
> </xsl:call-template>
> </xsl:for-each>
> </xsl:when>
> <xsl:otherwise>
> <xsl:call-template name="steps">
> <xsl:with-param name="compnum" select="$compnum + 1"/>
> <xsl:with-param name="stepindex" select="'1'"/>
> <xsl:with-param name="yoffset" select="$maxyoffset"/>
> <xsl:with-param name="maxyoffset" select="$maxyoffset"/>
> </xsl:call-template>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:when>
> <xsl:otherwise>
> <xsl:element name="wf:view">
> <xsl:element name="wf:maxy">
> <xsl:value-of select="$maxyoffset"/>
> </xsl:element>
> </xsl:element>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
> <xsl:template name="step">
> <xsl:param name="compnum"/>
> <xsl:param name="stepindex"/>
> <xsl:param name="yoffset"/>
> <xsl:param name="maxyoffset"/>
> <wf:step/>
> <xsl:call-template name="steps">
> <xsl:with-param name="compnum" select="$compnum"/>
> <xsl:with-param name="stepindex" select="$stepindex + 1"/>
> <xsl:with-param name="yoffset" select="$yoffset"/>
> <xsl:with-param name="maxyoffset" select="$maxyoffset"/>
> </xsl:call-template>
> </xsl:template>
> </xsl:stylesheet>
> -------------------------------------------------------------
> in.xml:
> <?xml version="1.0" encoding="utf-8"?>
> <wf:flow xmlns:wf="http://www.emeldi.com/tboss/hot-deploy/workflow"
> name="ANONYMOUS-2">
> <wf:step flow-name="ANONYMOUS-2" name="Step-1">
> <wf:next-steps>
> <wf:next-step result="A-2-R1" name="Success"/>
> <wf:next-step result="*" name="Error"/>
> </wf:next-steps>
> <wf:step-number>1</wf:step-number>
> <wf:component-number>1</wf:component-number>
> </wf:step>
> <wf:step flow-name="ANONYMOUS-2" name="Error">
> <wf:next-steps/>
> <wf:step-number>2</wf:step-number>
> <wf:component-number>1</wf:component-number>
> </wf:step>
> <wf:step flow-name="ANONYMOUS-2" name="Success">
> <wf:next-steps/>
> <wf:step-number>2</wf:step-number>
> <wf:component-number>1</wf:component-number>
> </wf:step>
> <wf:step flow-name="ANONYMOUS-2" name="Start">
> <wf:next-steps>
> <wf:next-step result="A-1-R1" name="Step-1"/>
> <wf:next-step result="*" name="Error"/>
> </wf:next-steps>
> <wf:step-number>0</wf:step-number>
> <wf:component-number>1</wf:component-number>
> </wf:step>
> <wf:components>
> <wf:component pos="1" start="Start">
> <wf:step-name>Start</wf:step-name>
> <wf:step-name>Step-1</wf:step-name>
> <wf:step-name>Error</wf:step-name>
> <wf:step-name>Success</wf:step-name>
> </wf:component>
> </wf:components>
> </wf:flow>
> -------------------------------------------------------------
> xalan-test.sh:
> #!/bin/sh
> # Please change this to put to your Xalan:
> XALAN_HOME=/usr/local/xalan-j_2_7_1
> CLASSPATH='.'
> for i in ${XALAN_HOME}/*.jar
> do
> CLASSPATH=$CLASSPATH:$i
> done
> # First the default
> ant default
> # Second the Xalan:
> export CLASSPATH
> ant xalan
> -------------------------------------------------------------
> <project name="xalan-problem" basedir="." default="default">
> <description>
> Shows a problem with XALAN processor
> </description>
> <target name="default">
> <xslt
> style="style.xsl"
> in="in.xml"
> out="out-default.xml"
> />
> </target>
> <target name="xalan">
> <xslt
> style="style.xsl"
> in="in.xml"
> out="out-xalan.xml"
> >
> <factory name="org.apache.xalan.processor.TransformerFactoryImpl"/>
> </xslt>
> </target>
> </project>
> -------------------------------------------------------------
> $ ./xalan-test.sh
> Buildfile: build.xml
> default:
> [xslt] Processing /home/vaclav/work/xalan-problem/in.xml to
> /home/vaclav/work/xalan-problem/out-default.xml
> [xslt] Loading stylesheet /home/vaclav/work/xalan-problem/style.xsl
> [xslt] : Warning!
> [xslt]
> COUNT=1
> BUILD SUCCESSFUL
> Total time: 0 seconds
> Buildfile: build.xml
> xalan:
> [xslt] Processing /home/vaclav/work/xalan-problem/in.xml to
> /home/vaclav/work/xalan-problem/out-xalan.xml
> [xslt] Loading stylesheet /home/vaclav/work/xalan-problem/style.xsl
> [xslt] /home/vaclav/work/xalan-problem/style.xsl:52:21: Warning!
> [xslt]
> COUNT=4
> BUILD SUCCESSFUL
> Total time: 0 seconds
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]