cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Sonney <ke...@webslingerz.com>
Subject Re: How to do logic in stylesheets?
Date Mon, 03 Jul 2000 16:20:27 GMT
On Mon, 3 Jul 2000, Ulrich Mayring wrote:
> Basically, I want something like:
> 
> <?cocoon-process type="xslt"?>
> <?cocoon-process type="xsp"?>
> 
> But I think this is not possible, is it?

Sure it is. I do it a lot. But you have to do something like the
examples. below. Note : All server names & special queries have been
changed or removed to protect the innocent. Props to Donald Ball for doing
this first. Cacheing *CAN* be a problem, but there are hacks to make
Cocoon re-gen the xsp page nearly every time.

<!-- Begin test.xml file -->
<?xml version="1.0"?>
<?xml-stylesheet href="wZ.xsl" type="text/xsl"?>

<?cocoon-process type="xslt"?>
<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>

<xsp:page 
	language="java"
	xmlns:xsp="http://www.apache.org/1999/XSP/Core"
	xmlns:sql="http://www.apache.org/1999/SQL"
	xmlns:wZ="http://www.webslingerZ.com/XML"
>

<page>
<!-- Specify the final xsl file -->
<wZ:stylesheet href="test.xsl" />

 <ldap-defs>
  <ldap-server name="unc-cas">
   <initializer>com.sun.jndi.ldap.LdapCtxFactory</initializer>
	<ldap-serverurl>ldap://some.ldap.server</ldap-serverurl>
  </ldap-server>
 </ldap-defs>

 <ldap-query server="unc-cas" ldap-searchbase="o=webslingerZ,c=US" doc-element="wZ:user"
row-element="wZ:ldapResult">
 sn=Sonney* 
 </ldap-query>
</page>
</xsp:page>
<!-- End test.xml -->

<!--Begin wZ.xsl -->
<?xml version="1.0"?>

<xsl:stylesheet
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:sql="http://www.apache.org/1999/SQL"
	xmlns:wZ="http://www.webslingerZ.com/XML"
version="1.0">

<!-- Remember that xsl file? This is where we build the pi for it. -->
<xsl:template match="/">
	<xsl:if test="//wZ:stylesheet">
		<xsl:processing-instruction name="xml-stylesheet">type=&quot;text/xsl&quot;
href=&quot;<xsl:value-of select="//wZ:stylesheet/@href"/>&quot;</xsl:processing-instruction>
	</xsl:if>
	<xsl:apply-templates/>
</xsl:template>


<!-- settings to copy the unaffected tags --> 
<xsl:template match="@*|node()" priority="-1">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

<!-- get the user data -->
<xsl:template match="wZ:user">
	<xsl:for-each select="wZ:ldapResult">
	<sql:execute-query>
	<!-- some query here dependant on ldap data -->
	</sql:execute-query>
	</xsl:for-each>
</xsl:template>

<xsl:template match="wZ:stylesheet"></xsl:template>

<!-- rebuild remaining PIs -->
<xsl:template match="processing-instruction()">
	<xsl:if test="not(name(.)='xml-stylesheet')">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
	</xsl:if>
</xsl:template>
</xsl:stylesheet>
<!-- End wZ.xsl -->

<!-- begin test.xsl -->
<?xml version="1.0"?>

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

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="page">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"/>
  <title>Test Page</title>
 </head>
 <body>
	<table>
		<tr><th>Name</th><th>Address</th></tr>
		<xsl:apply-templates />
	</table>	
 </body>
</html>
</xsl:template>

<xsl:template match="rowset">
		<xsl:for-each select="row">
			<xsl:sort select="name"/>
				<tr><td><xsl:value-of select="name"/></td>
				<td><xsl:value-of select="address"/></td></tr>
		</xsl:for-each>
</xsl:template>


</xsl:stylesheet>
<!-- End test.xsl -->
-- 
- Kevin Sonney
  kevin@webslingerZ.com


Mime
View raw message