Here is an example of a poll. Given a poll content piece like:
<?xml version="1.0" encoding="UTF-8"?>
<poll id="pollUID">
<question>
<p>[ Question 1 ]</p>
</question>
<answer id="a1UID">
<p>Agree</p>
</answer>
<answer id="a2UID">
<p>Disagree</p>
</answer>
</poll>This is used to populate the Poll feature/data in Jive Forums webapp. The authorized author does not use the Jive admin interface, rather, they stay in the CMS to create the poll content piece and assign it to a page. The XSL below is used for providing runtime Velocity code for:
a.) adding the poll to the Jive DB at runtime if it does not exist b.) display the poll form if the user has not taken it, or c.) display the results if the user has taken it
(the $xmlpoll is a Velocity request scoped Tool)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!--
-->
<xsl:template match="answer" mode="addOptionsToDb">
<xsl:text>$xmlpoll.addOption("</xsl:text>
<xsl:value-of select="normalize-space(.)"/>
<xsl:text>")</xsl:text>
</xsl:template>
<!--
-->
<xsl:template match="answer" mode="setOptionsToDb">
<xsl:text>$xmlpoll.setOption(</xsl:text>
<xsl:value-of select="position() - 1"/>
<xsl:text>, "</xsl:text>
<xsl:value-of select="normalize-space(.)"/>
<xsl:text>")</xsl:text>
</xsl:template>
<!--
-->
<xsl:template match="poll">
<xsl:param name="xml_id" select="''"/>
<xsl:variable
name="poll_md"
select="document(concat('metadata/content/', $xml_id, '.xml'))/s:md-content"/>
<xsl:comment>
#set ($pollName = "<xsl:value-of select="$xml_id"/>")
#set ($poll = $xmlpoll.getPoll($pollName))#if ($poll)
#if ($xmlpoll.isModified("<xsl:value-of select="$poll_md/@modified"/>"))
$xmlpoll.setDescription("<xsl:value-of select="question/simpleText"/>")
<xsl:apply-templates select="answer" mode="setOptionsToDb"/>
#end
#else
#set ($poll = $xmlpoll.createPoll($pollName))
$xmlpoll.setDescription("<xsl:value-of select="question/simpleText"/>");
<xsl:apply-templates select="answer" mode="addOptionsToDb"/>
#end
</xsl:comment>
<div class="section" xmlns="http://www.w3.org/1999/xhtml">
<h2>Poll</h2>
<xsl:comment>
#if ($isMember)
#if (!$xmlpoll.hasUserVoted($pageUser))
#if ($request.getParameter("doSave"))#set ($answer = $request.getParameter("q<xsl:value-of select="$xml_id"/>"))
$xmlpoll.addUserVote($answer, $pageUser)
#else
</xsl:comment>
<form action="{$lsb_focus_nodeset/@name}" method="post" id="form_{$xml_id}">
<xsl:if test="boolean(@bg_img)">
<xsl:attribute name="style">
<xsl:text>background-image:/images/</xsl:text>
<xsl:value-of select="@bg_img"/>
</xsl:attribute>
</xsl:if> <xsl:apply-templates select="question" mode="not_saved">
<xsl:with-param name="mc_id" select="$xml_id"/>
</xsl:apply-templates> <xsl:apply-templates select="answer" mode="not_saved">
<xsl:with-param name="mc_id" select="$xml_id"/>
</xsl:apply-templates><input type="submit" value="Vote" name="doSave"/>
<input type="hidden" name="quiz_id" id="quiz_id" value="{$xml_id}"/>
</form>
<xsl:comment>
#end
#end
#end
</xsl:comment> <xsl:comment>
#if ($xmlpoll.hasUserVoted($pageUser) || !$isMember)
</xsl:comment> <xsl:apply-templates select="question" mode="not_saved">
<xsl:with-param name="mc_id" select="$xml_id"/>
</xsl:apply-templates> <xsl:comment>
#if (!$isMember)
</xsl:comment><p><em>Only members can vote in polls.</em></p>
<xsl:comment>
#end
#set ($results = $xmlpoll.getResults())
#foreach ($result in $results)
</xsl:comment><div>${result.num}. ${result.question} - ${result.voteCount} votes ${result.percentage}%</div>
<xsl:comment>
#end
#end
</xsl:comment></div> </xsl:template> <!-- --> </xsl:stylesheet>
Robert Koberg wrote:
QM wrote: (snip :)
: to know your thoughts regarding pregenerating JSP or velocity templates : such that the decoration (and content inclusion) happens prior to runtime.
I don't think I understand what you're after here, but it's a little early in the morning for me =) Please, explain again.
: For example, we use XSLT to pregenerate the pages (managed through our : CMS) so that as much as possible exists in the page/template. This : leaves only what is *required* to be dynamic for runtime. Thoughts? (I : can take it :)
I suppose what I don't understand is, what is "dynamic" here? Are you talking a menu that's regenerated at each request (in case new menu items have been added) or something else?
(Perhaps I should have changed the subject line)
Are you familiar with apache Forrest? You know how they generate a static site, right? Well, think of that, but instead generating XHTML it generates Velocity or JSP pages to be used on a live site (after going through a QA site first, of course :). In a way, it is a cache. (Our CMS does the similar things as Forrest)
In the case of new menu items being added, it is done through the CMS (or by hand) and all of the appropriate pages that need to contain that item are re-pre-generated.
For example, we have a web app that has quite a few (80-90%) content heavy pages where the only thing that needs to be dynamic is the user's username displaying and that user's particular choice of CSS files. Instead of 'decoratorating' at runtime, it is already decorated, the content already exists on the page and the only dynamic things are minor. XSLT is used for decoration prior to runtime. At runtime (I guess a term left over from my CDROM days), no XSLT is used, rather the pregenerated Velocity page/templates (or JSP, but angle brackets tend to make for more work with regard to XSLT/XML).
best, -Rob
-QM
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
