You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "Sinvhal, Swapnil" <Sw...@hpsglobal.com> on 2000/11/01 11:49:39 UTC
xsp:logic in XSL
Hi, Cocoon - users !!
I am trying to apply the <xsp:logic> tag in XSL.
But the generated HTML shows up the JAVA code as such - it does not process
it.
I have to display a list of sections.
After every 5 sections , I need a <BR> tag.
What am I doing wrong ?
======================
THE XML file is :
<?xml version="1.0"?>
<!-- Author: Swapnil Sinvhal -->
<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
<?cocoon-format type="text/xml"?>
<?xml-stylesheet type="text/xsl" href="SectionLinks.xsl"?>
<xsp:page language="java" xmlns:xsp="http://www.apache.org/1999/XSP/Core">
<sections>
<xsp:logic>
String linkData = null;
String hrefData = null;
String linkKey = null;
String hrefKey = null;
int i =0;
for(i=1; ; i++)
{
linkKey = "sectionLink." + i;
hrefKey = "ahrefLink." + i;
linkData=
(String)(((Hashtable)request.getAttribute("data")).get(linkKey));
hrefData =
(String)(((Hashtable)request.getAttribute("data")).get(hrefKey));
if ((hrefData==null)||(linkData==null)) break;
if (!(hrefData.equals("")))
{
<section>
<sectionLink><xsp:expr>linkData</xsp:expr></sectionLink>
<ahrefLink><xsp:expr>hrefData</xsp:expr></ahrefLink>
</section>
}
}
</xsp:logic>
</sections>
</xsp:page>
==============================
The XSL file is :
******************************
<xsl:template match="/">
<table align="left" height="100%" width="100%" cellpadding="0"
cellspacing="0">
<tr align="left" valign="top" class="tdc" height="100%" width="70%">
<td CLASS="cityBkgd">
<xsp:logic>
<![CDATA[
private int count = 0;
]]>
<xsl:for-each select="sections/section">
<xsp:logic>
<![CDATA[
count += 1;
if (count==5)
{
]]>
</xsp:logic>
<BR />
<xsp:logic>
<![CDATA[
}
else
{
]]>
</xsp:logic>
<xsl:element name = "A">
<xsl:attribute name = "id">
SectionLink
</xsl:attribute>
<xsl:attribute name = "href">
<xsl:value-of select="ahrefLink"/>
</xsl:attribute>
<B>
<xsl:value-of select="sectionLink"/>
</B>
</xsl:element>
<xsp:logic>
<![CDATA[
}
]]>
</xsp:logic>
<font color = "#ffffff" size = "2" face = "Arial">
<B>  |  </B>
</font>
</xsl:for-each>
</xsp:logic>
</td>
<td align="left" valign="top" class="tdc" height="100%"
width="30%">
  
</td>
</tr>
</table>
</xsl:template>
</xsp:page>
</xsl:stylesheet>
*************************************************************
Thanks a lot.
Regards,
Swapnil
Re: xsp:logic in XSL
Posted by Konstantin Piroumian <KP...@flagship.ru>.
xsp:logic in XSLFirst, as it was said before, you cannot put Java code into your formatting stylesheet.
The second, there must be a logicsheet to combine XSL and XSP. If you are designing your XSL file as a logicsheet, so it is not properly designed. Look at the samples for more info.
And the third, such things (like adding <br>-s etc., can be done by pure XSL whithout any XSP and Java.
You can do it like this:
<xsl:template match="/">
<table align="left" height="100%" width="100%" cellpadding="0" cellspacing="0">
<tr align="left" valign="top" class="tdc" height="100%" width="70%">
<td CLASS="cityBkgd">
<xsl:for-each select="sections/section">
<xsl:if test="position() mod 5 = 0"><br/></xsl:if>
<a id="SectionLink" href="{ahrefLink}">
<b><xsl:value-of select="sectionLink"/></b>
</a>
<!--
<xsl:element name = "A">
<xsl:attribute name = "id">
SectionLink
</xsl:attribute>
<xsl:attribute name = "href">
<xsl:value-of select="ahrefLink"/>
</xsl:attribute>
<B>
</B>
</xsl:element>
-->
...
</xsl:for-each>
</td>
<td align="left" valign="top" class="tdc" height="100%" width="30%">
  
</td>
</tr>
</table>
</xsl:template>
For XSL questions use XSL mail list.
Regards,
Konstantin Piroumian.
----- Original Message -----
From: Sinvhal, Swapnil
To: 'cocoon-users@xml.apache.org'
Cc: 'greenrd@hotmail.com'
Sent: 1 ноября 2000 г., среда 13:49
Subject: xsp:logic in XSL
Hi, Cocoon - users !!
I am trying to apply the <xsp:logic> tag in XSL.
But the generated HTML shows up the JAVA code as such - it does not process it.
I have to display a list of sections.
After every 5 sections , I need a <BR> tag.
What am I doing wrong ?
======================
THE XML file is :
<?xml version="1.0"?>
<!-- Author: Swapnil Sinvhal -->
<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
<?cocoon-format type="text/xml"?>
<?xml-stylesheet type="text/xsl" href="SectionLinks.xsl"?>
<xsp:page language="java" xmlns:xsp="http://www.apache.org/1999/XSP/Core">
<sections>
<xsp:logic>
String linkData = null;
String hrefData = null;
String linkKey = null;
String hrefKey = null;
int i =0;
for(i=1; ; i++)
{
linkKey = "sectionLink." + i;
hrefKey = "ahrefLink." + i;
linkData= (String)(((Hashtable)request.getAttribute("data")).get(linkKey));
hrefData = (String)(((Hashtable)request.getAttribute("data")).get(hrefKey));
if ((hrefData==null)||(linkData==null)) break;
if (!(hrefData.equals("")))
{
<section>
<sectionLink><xsp:expr>linkData</xsp:expr></sectionLink>
<ahrefLink><xsp:expr>hrefData</xsp:expr></ahrefLink>
</section>
}
}
</xsp:logic>
</sections>
</xsp:page>
==============================
The XSL file is :
******************************
<xsl:template match="/">
<table align="left" height="100%" width="100%" cellpadding="0" cellspacing="0">
<tr align="left" valign="top" class="tdc" height="100%" width="70%">
<td CLASS="cityBkgd">
<xsp:logic>
<![CDATA[
private int count = 0;
]]>
<xsl:for-each select="sections/section">
<xsp:logic>
<![CDATA[
count += 1;
if (count==5)
{
]]>
</xsp:logic>
<BR />
<xsp:logic>
<![CDATA[
}
else
{
]]>
</xsp:logic>
<xsl:element name = "A">
<xsl:attribute name = "id">
SectionLink
</xsl:attribute>
<xsl:attribute name = "href">
<xsl:value-of select="ahrefLink"/>
</xsl:attribute>
<B>
<xsl:value-of select="sectionLink"/>
</B>
</xsl:element>
<xsp:logic>
<![CDATA[
}
]]>
</xsp:logic>
<font color = "#ffffff" size = "2" face = "Arial">
<B>  |  </B>
</font>
</xsl:for-each>
</xsp:logic>
</td>
<td align="left" valign="top" class="tdc" height="100%" width="30%">
  
</td>
</tr>
</table>
</xsl:template>
</xsp:page>
</xsl:stylesheet>
*************************************************************
Thanks a lot.
Regards,
Swapnil