ovidiu 2002/09/05 17:23:49 Modified: src/java/org/apache/cocoon/components/language/markup/xsp/java jpath.xsl Log: Correctly handle the situation where the same XPath expression is used in multiple places in an XSP page. Correctly handle boolean values of JXPath expressions. Revision Changes Path 1.2 +33 -11 xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/jpath.xsl Index: jpath.xsl =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/jpath.xsl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- jpath.xsl 19 May 2002 19:19:39 -0000 1.1 +++ jpath.xsl 6 Sep 2002 00:23:49 -0000 1.2 @@ -12,6 +12,11 @@ xmlns:jpath="http://apache.org/xsp/jpath/1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + <xsl:key name="JPathExprs" match="jpath:if" use="@test"/> + <xsl:key name="JPathExprs" match="jpath:when" use="@test"/> + <xsl:key name="JPathExprs" match="jpath:for-each" use="@select"/> + <xsl:key name="JPathExprs" match="jpath:value-of" use="@select"/> + <xsl:template match="xsp:page"> <xsp:page> <xsl:apply-templates select="@*"/> @@ -33,9 +38,15 @@ WebContinuation kont = (WebContinuation)((Environment)resolver).getAttribute("kont"); JXPathContext jxpathContext = JXPathContext.newContext(bean); + Object __jxpathResult; // Generate the compiled representation of the JXPath // expressions used by this page. - <xsl:apply-templates mode="compile"/> + <xsl:apply-templates + select="(//jpath:if | //jpath:when) + [generate-id(.) = generate-id(key('JPathExprs', @test)[1])] + | (//jpath:for-each | //jpath:value-of) + [generate-id(.) = generate-id(key('JPathExprs', @select)[1])]" + mode="compile"/> </xsp:init-page> <xsl:apply-templates/> @@ -64,23 +75,30 @@ <xsl:apply-templates select="jpath:*" mode="compile"/> </xsl:template> + <!-- <xsl:template match="*|@*|text()|processing-instruction()" mode="compile"> <xsl:apply-templates mode="compile"/> </xsl:template> +--> <xsl:template name="get-var-name"> <xsl:param name="expr"/> - jxpath_<xsl:value-of select="translate($expr, ' 	

~`!@%^*()-+=[]{}\|,./?><', '')"/> + jxpath_<xsl:value-of select="translate($expr, " 	

~`!@%^*()-+=[]{}\|,./?><'", '')"/> </xsl:template> <xsl:template match="jpath:if"> <xsl:choose> <xsl:when test="@test"> <xsp:logic> - if (<xsl:call-template name="get-var-name"> - <xsl:with-param name="expr" select="@test"/> - </xsl:call-template> - .getValue(jxpathContext) != null) { + + __jxpathResult = <xsl:call-template name="get-var-name"> + <xsl:with-param name="expr" select="@test"/> + </xsl:call-template> + .getValue(jxpathContext); + if ((__jxpathResult instanceof Boolean + && ((Boolean)__jxpathResult).booleanValue() == true) + || (!(__jxpathResult instanceof Boolean) + && __jxpathResult != null)) { <xsl:apply-templates/> } </xsp:logic> @@ -96,7 +114,7 @@ <xsl:template match="jpath:choose"> <xsp:logic> - if (0) { + if (false) { } <xsl:apply-templates select="jpath:when|jpath:otherwise"/> </xsp:logic> @@ -105,10 +123,14 @@ <xsl:template match="jpath:when"> <xsp:logic> - else if (<xsl:call-template name="get-var-name"> - <xsl:with-param name="expr" select="@test"/> - </xsl:call-template> - .getValue(jxpathContext) != null) { + else if ((((__jxpathResult = <xsl:call-template name="get-var-name"> + <xsl:with-param name="expr" select="@test"/> + </xsl:call-template> + .getValue(jxpathContext)) + instanceof Boolean) + && ((Boolean)__jxpathResult).booleanValue() == true) + || (!(__jxpathResult instanceof Boolean) + && __jxpathResult != null)) { <xsl:apply-templates/> } </xsp:logic>
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]