You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Sundeep Kapadia <sk...@wysdom.com> on 2000/10/12 15:31:38 UTC

Problem "slicing up" my XML Document

Hi,

I'm trying to display a list of categories in a set of columns for a web
stylesheet.  I'm attempting to display it in a table.  The problem I'm
having is "slicing up" my list of categories.

Here's my code that I'm trying to run:


		<table>
		<tr>
	        <xsl:for-each select="CAT_LIST/CATEGORY">
			    <td>
				    <xsl:element name="a">
						<xsl:attribute name="href">
						    <xsl:value-of
select="URL"/>
						</xsl:attribute>
						<xsl:value-of
select="TITLE"/>
				    </xsl:element>
				</td>
				<!-- code in question -->
				<xsl:if test="position() mod 3 = 0">
					</tr>
					<tr>
				</xsl:if>
				<!-- code in question -->
	        </xsl:for-each>
		</tr>
		</table>

I'm attempting to end my table row after 3 categories but I get a compile
error.  If I run through the logic of my algorithm, it's correct.  It's a
matter of syntax whenever I try to close one table row and open up another.

Does anyone know how to do this?  I've been trying for over 2 hours now and
nothing has worked!!!

Thanx,

Sundeep Kapadia
Wysdom Inc.
905-763-6979 ext. 2371
skapadia@wysdom.com

Re: Problem "slicing up" my XML Document

Posted by Berin Loritsch <bl...@infoplanning.com>.
----- Original Message ----- 
From: "Sundeep Kapadia" <sk...@wysdom.com>
To: <co...@xml.apache.org>
Sent: Thursday, October 12, 2000 9:31 AM
Subject: Problem "slicing up" my XML Document


> Hi,
> 
> I'm trying to display a list of categories in a set of columns for a web
> stylesheet.  I'm attempting to display it in a table.  The problem I'm
> having is "slicing up" my list of categories.
> 
> Here's my code that I'm trying to run:
> 
> 
> <table>
> <tr>
>         <xsl:for-each select="CAT_LIST/CATEGORY">
>     <td>
>     <xsl:element name="a">
> <xsl:attribute name="href">
>     <xsl:value-of
> select="URL"/>
> </xsl:attribute>
> <xsl:value-of
> select="TITLE"/>
>     </xsl:element>
> </td>
> <!-- code in question -->
> <xsl:if test="position() mod 3 = 0">
> </tr>
> <tr>
> </xsl:if>
> <!-- code in question -->
>         </xsl:for-each>
> </tr>
> </table>
> 
> I'm attempting to end my table row after 3 categories but I get a compile
> error.  If I run through the logic of my algorithm, it's correct.  It's a
> matter of syntax whenever I try to close one table row and open up another.
> 
> Does anyone know how to do this?  I've been trying for over 2 hours now and
> nothing has worked!!!

The issue here is that you are violating XML.  You can't close and open tags
inside another tag.  I will include some code that works just as well, and
might be cleaner.

<table>
  <xsl:for-each select="CAT_LIST/CATEGORY">
    <tr>
      <td>
        <a href="{./URL}"><xsl:value-of select="./TITLE"/></a>
      </td>
      <td>
        <xsl:choose>
          <xsl:when test=".[position() + 1]">
            <a href=".[position() + 1]/URL"><xsl:value-of select=".[position() + 1]/TITLE"/></a>
          </xsl:when>
          <xsl:otherwise>
            &#160;
          </xsl:otherwise>
        </xsl:choose>
      </td>
      <td>
        <xsl:choose>
          <xsl:when test=".[position() + 2]">
            <a href=".[position() + 2]/URL"><xsl:value-of select=".[position() + 2]/TITLE"/></a>
          </xsl:when>
          <xsl:otherwise>
            &#160;
          </xsl:otherwise>
        </xsl:choose>
      </td>
    </tr>
  </xsl:for-each>
</table>



Re: Problem "slicing up" my XML Document

Posted by Ulrich Mayring <ul...@denic.de>.
Sundeep Kapadia wrote:
> 
>                     <xsl:if test="position() mod 3 = 0">
>                          </tr>
>                          <tr>
>                     </xsl:if>

This is wrong, you cannot close a tag and then open it. Every open tag
must be closed in XML. For further information please refer to your XSLT
documentation, not this list, which is not about XSLT, but about cocoon.

Ulrich

-- 
Ulrich Mayring
DENIC eG, Systementwicklung