OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

docbook-apps message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]

Subject: RE: [docbook] Showing/Hiding QandA answers

Sure, here is a non-working example. The basic idea is some object would
have an onclick attribute to call showAnswer(id), where id is the xml:id
of the answer. The idea for the answer is being placed in an anchor tag
rather than around the answer, so even if the onclick functionality
worked, it wouldn't target the right object.

Given this docbook input:

<qandaset xml:id='qa' defaultlabel='number'>
		<question><para>2 + 4 = ?</para></question>
		<answer><para role='hiddenanswer'
		<question><para>8 - 4 = ?</para></question>
		<answer><para role='hiddenanswer'

With this html output (non-relevent html removed for brevity):

<table border="0" width="100%" summary="Q and A Set">
          <col align="left" width="1%" />
          <col />
            <tr class="question" title="1.">
              <td align="left" valign="top">
                <a id="id284838"></a>
                <a id="id284837"></a>
              <td align="left" valign="top">
                <p>2 + 4 = ?</p>
            <tr class="answer">
              <td align="left" valign="top"></td>
              <td align="left" valign="top">
                <p class="hiddenanswer"><a id="a1"></a>6</p>
            <tr class="question" title="2.">
              <td align="left" valign="top">
                <a id="id284842"></a>
                <a id="id284840"></a>
              <td align="left" valign="top">
                <p>8 - 4 = ?</p>
            <tr class="answer">
              <td align="left" valign="top">
                <a id="a2"></a>
              <td align="left" valign="top">
                <p class="hiddenanswer">4</p>

This was transformed using this stylesheet:

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:d='http://docbook.org/ns/docbook' exclude-results-prefixes='d'
version='1.0'> <xsl:import
href='/usr/share/sgml/docbook/xsl-ns-stylesheets/xhtml/onechunk.xsl' />
<xsl:template name="user.head.content">
	<script src="docbok.js" type="text/javascript"></script>
</xsl:template> </xsl:stylesheet>

function showAnswer(id) {
	if (document.getElementById(id).style.display=='block'){
		document.getElementById(id).style.display = 'none';}
	else {
		document.getElementById(id).style.display = 'block';}

	.hiddenanswer {
	display: none;

Output created using xsltproc. The only params set were for the
stylesheet and indented output.

-----Original Message-----
From: Bob Stayton [mailto:bobs@sagehill.net] 
Sent: Wednesday, January 25, 2012 3:49 PM
To: DocBook Apps; David Goss
Subject: Re: [docbook] Showing/Hiding QandA answers

[redirecting this to the docbook-apps mailing list where stylesheet
issues are discussed]

Hi David,
I get the general idea, I'm not completely clear on the specifics here.
Can you provide a short sample of the question/answer DocBook input and
what you want its HTML output to look like?  Are you using any of the
qanda stylesheet params, such as qanda.defaultlabel?

Bob Stayton
Sagehill Enterprises

----- Original Message -----
From: "David Goss" <dgoss@mueller-inc.com>
To: <docbook@lists.oasis-open.org>
Sent: Tuesday, January 24, 2012 9:33 AM
Subject: [docbook] Showing/Hiding QandA answers

I am trying to replace the answers of QandA sets in HTML output to hide
by default and only show when the user clicks a "show answer" link. This
is trivial to do with HTML/Javascript:

<style type="text/css">
.answer {display: none;}
<script type="text/javascript">
function showAnswer(id) {

document.getElementById(id).style.display = 'none';}
else {

document.getElementById(id).style.display = 'block';}
What is on my desk? <a href='#' onclick="showAnswer('a1');">show
answer</a><span class='answer' id='a1'></span>

To get this output in docbook->HTML, I've added this to my stylesheet
<xsl:template name="user.head.content">
<script src="myscript.js" type="text/javascript"></script>

In the docbook source, I've change the role of answer to "hidden-answer"
and change the display type for .hidden-answer to none in my CSS.

Now to get the onclick="showAnswer(a1)" part into links. The HTML output
sets an empty anchor tag with the answer's id next to it, but not around
it. This is the part where I'm stuck...

Maybe there's a better way to accomplish this using a template on

DAVID GOSS | Technical Writer
P 1.800.876.9218 x 345 | F 1.800.588.9866

To unsubscribe, e-mail: docbook-unsubscribe@lists.oasis-open.org
For additional commands, e-mail: docbook-help@lists.oasis-open.org

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]