You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Robert Taylor (JIRA)" <xa...@xml.apache.org> on 2004/11/05 11:36:32 UTC

[jira] Created: (XALANJ-1983) last() inside for-each causes strange behavior

last() inside for-each causes strange behavior
----------------------------------------------

         Key: XALANJ-1983
         URL: http://nagoya.apache.org/jira/browse/XALANJ-1983
     Project: XalanJ2
        Type: Bug
  Components: Xalan  
    Versions: 2.6    
 Environment: Win2k JDK1.4.2
    Reporter: Robert Taylor


What I want is to render 2 columns of data where each
column contains rows with x number of values. For this example 4 
values.
If the row contains less than 4 values, then render an empty place 
holder
cell.

Here is what I get when I view the xml file transformed using a web
browser:

AAA BBB CCC DDD   AAA BBB CCC DDD
AAA BBB CCC DDD   AAA BBB CCC DDD
AAA BBB CCC DDD   AAA BBB CCC DDD
AAA BBB CCC       AAA BBB CCC

This is the expected behavior.



Here is what I get when I view the xml file transformed with Xalan 
2.6.0:

AAA AAA BBB CCC   DDD
AAA AAA BBB CCC   DDD
AAA AAA BBB CCC
AAA AAA BBB CCC

Only the first value in each row of the first column is rendered.
The second column row values have "shifted" to the left.


Here is what I get when I view the xml file transformed with Xalan 
2.6.0
without the offending XSL last().

AAA BBB CCC DDD   AAA BBB CCC DDD
AAA BBB CCC DDD   AAA BBB CCC DDD
AAA BBB CCC DDD   AAA BBB CCC DDD
AAA BBB CCC AAA   BBB CCC

This is expected behavior because the code which renders the
place holder cells (which uses the last())is commented out.



Here is the xml:
<?xml version="1.0"?>
<data>
  <item>AAA</item>
  <item>BBB</item>
  <item>CCC</item>
  <item>DDD</item>
  <item>AAA</item>
  <item>BBB</item>
  <item>CCC</item>
  <item>DDD</item>
  <item>AAA</item>
  <item>BBB</item>
  <item>CCC</item>

</data>

Here is the xsl:
<?xml version="1.0" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<head>
<title>Output</title>
</head>
<body>
<table border="1">
<tr>
 <td>  </td>
 <td>  </td>
 <td>  </td>
 <td>  </td>
 <td rowspan="10">  </td>
 <td>  </td>
 <td>  </td>
 <td>  </td>
 <td>  </td>
</tr>
<xsl:apply-templates/>
</table>
</body>
</html>
</xsl:template>

<xsl:template match="data">
<xsl:for-each select="item[position() mod 4 = 1]">
<tr>

<!-- Render values -->
<xsl:for-each select=".|following-sibling::item[position() &lt; 4]">
<td>
<xsl:value-of select="."/>
</td>

<!-- render any buffer cells --> <!-- This is the problem code -->
<xsl:if test="(last() &lt; 4) and (last() = position())">

 <xsl:call-template name="loop">
  <xsl:with-param name="repeat" select="number(4-last())"/>
 </xsl:call-template>

</xsl:if>
</xsl:for-each>

<!-- Render values -->
<xsl:for-each select=".|following-sibling::item[position() &lt; 4]">
<td><xsl:value-of select="."/></td>
</xsl:for-each>

</tr>
</xsl:for-each>
</xsl:template>


<!-- Recursive for-loop -->
<xsl:template name="loop">
<xsl:param name="repeat">0</xsl:param>
<xsl:if test="number($repeat) >= 1">
 <td>  </td>
  <xsl:call-template name="loop">
  <xsl:with-param name="repeat" select="$repeat - 1"/>
  </xsl:call-template>
</xsl:if>
</xsl:template>

</xsl:stylesheet>



I have made sure that the program is using the correct Xalan version by
placing the xalan.jar, xercesImpl.jar, and xml-apis.jar in the
JAVA_HOME/lib/endorsed.

I have also included calls to EnvironmentCheck which displays the 
version
of Xalan which is 2.6.0.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://nagoya.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org


[jira] Commented: (XALANJ-1983) last() inside for-each causes strange behavior

Posted by "Robert Taylor (JIRA)" <xa...@xml.apache.org>.
     [ http://nagoya.apache.org/jira/browse/XALANJ-1983?page=comments#action_55083 ]
     
Robert Taylor commented on XALANJ-1983:
---------------------------------------

Please note that when I entered this bug, JIRA
munged the formatting of the table structure 
in the following section:

<section>
Here is what I get when I view the xml file transformed using a web
browser:

AAA BBB CCC DDD AAA BBB CCC DDD
AAA BBB CCC DDD AAA BBB CCC DDD
AAA BBB CCC DDD AAA BBB CCC DDD
AAA BBB CCC     AAA BBB CCC

This is the expected behavior. 
</section>

In case it does it again, the table structure
should be 4 rows, where each column contains
the same letter grouping (AAA, BBB, etc...).
Columns 4 and 8 should only contain 3 rows
of DDD.


The examples displayed below this in the orignal
message appear correctly.

> last() inside for-each causes strange behavior
> ----------------------------------------------
>
>          Key: XALANJ-1983
>          URL: http://nagoya.apache.org/jira/browse/XALANJ-1983
>      Project: XalanJ2
>         Type: Bug
>   Components: Xalan
>     Versions: 2.6
>  Environment: Win2k JDK1.4.2
>     Reporter: Robert Taylor

>
> What I want is to render 2 columns of data where each
> column contains rows with x number of values. For this example 4 
> values.
> If the row contains less than 4 values, then render an empty place 
> holder
> cell.
> Here is what I get when I view the xml file transformed using a web
> browser:
> AAA BBB CCC DDD   AAA BBB CCC DDD
> AAA BBB CCC DDD   AAA BBB CCC DDD
> AAA BBB CCC DDD   AAA BBB CCC DDD
> AAA BBB CCC       AAA BBB CCC
> This is the expected behavior.
> Here is what I get when I view the xml file transformed with Xalan 
> 2.6.0:
> AAA AAA BBB CCC   DDD
> AAA AAA BBB CCC   DDD
> AAA AAA BBB CCC
> AAA AAA BBB CCC
> Only the first value in each row of the first column is rendered.
> The second column row values have "shifted" to the left.
> Here is what I get when I view the xml file transformed with Xalan 
> 2.6.0
> without the offending XSL last().
> AAA BBB CCC DDD   AAA BBB CCC DDD
> AAA BBB CCC DDD   AAA BBB CCC DDD
> AAA BBB CCC DDD   AAA BBB CCC DDD
> AAA BBB CCC AAA   BBB CCC
> This is expected behavior because the code which renders the
> place holder cells (which uses the last())is commented out.
> Here is the xml:
> <?xml version="1.0"?>
> <data>
>   <item>AAA</item>
>   <item>BBB</item>
>   <item>CCC</item>
>   <item>DDD</item>
>   <item>AAA</item>
>   <item>BBB</item>
>   <item>CCC</item>
>   <item>DDD</item>
>   <item>AAA</item>
>   <item>BBB</item>
>   <item>CCC</item>
> </data>
> Here is the xsl:
> <?xml version="1.0" ?>
> <xsl:stylesheet version="1.0" xmlns:xsl="
> http://www.w3.org/1999/XSL/Transform">
> <xsl:template match="/">
> <html>
> <head>
> <title>Output</title>
> </head>
> <body>
> <table border="1">
> <tr>
>  <td>  </td>
>  <td>  </td>
>  <td>  </td>
>  <td>  </td>
>  <td rowspan="10">  </td>
>  <td>  </td>
>  <td>  </td>
>  <td>  </td>
>  <td>  </td>
> </tr>
> <xsl:apply-templates/>
> </table>
> </body>
> </html>
> </xsl:template>
> <xsl:template match="data">
> <xsl:for-each select="item[position() mod 4 = 1]">
> <tr>
> <!-- Render values -->
> <xsl:for-each select=".|following-sibling::item[position() &lt; 4]">
> <td>
> <xsl:value-of select="."/>
> </td>
> <!-- render any buffer cells --> <!-- This is the problem code -->
> <xsl:if test="(last() &lt; 4) and (last() = position())">
>  <xsl:call-template name="loop">
>   <xsl:with-param name="repeat" select="number(4-last())"/>
>  </xsl:call-template>
> </xsl:if>
> </xsl:for-each>
> <!-- Render values -->
> <xsl:for-each select=".|following-sibling::item[position() &lt; 4]">
> <td><xsl:value-of select="."/></td>
> </xsl:for-each>
> </tr>
> </xsl:for-each>
> </xsl:template>
> <!-- Recursive for-loop -->
> <xsl:template name="loop">
> <xsl:param name="repeat">0</xsl:param>
> <xsl:if test="number($repeat) >= 1">
>  <td>  </td>
>   <xsl:call-template name="loop">
>   <xsl:with-param name="repeat" select="$repeat - 1"/>
>   </xsl:call-template>
> </xsl:if>
> </xsl:template>
> </xsl:stylesheet>
> I have made sure that the program is using the correct Xalan version by
> placing the xalan.jar, xercesImpl.jar, and xml-apis.jar in the
> JAVA_HOME/lib/endorsed.
> I have also included calls to EnvironmentCheck which displays the 
> version
> of Xalan which is 2.6.0.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://nagoya.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org