This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Is this possible in XSL?
- To: Cihan dot Uslu at med dot ge dot com
- Subject: [xsl] Re: Is this possible in XSL?
- From: Dimitre Novatchev <dnovatchev at yahoo dot com>
- Date: Tue, 2 Oct 2001 21:38:14 -0700 (PDT)
- Cc: xsl-list at lists dot mulberrytech dot com
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Cihan,
The following stylesheet uses a "permutations" template to produce all permutations
of the values of nodes of the node-set that is passed to it as a parameter:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:call-template name="permutations">
<xsl:with-param name="nodes" select="assessment/question/answer/@item-id"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="permutations">
<xsl:param name="nodes" select="/.."/>
<xsl:param name="current"/>
<xsl:param name="delimiter" select="';'"/>
<xsl:choose>
<xsl:when test="not($nodes)">
<xsl:value-of select="concat($current, $delimiter)"/>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$nodes">
<xsl:variable name="thisPosition" select="position()"/>
<xsl:call-template name="permutations">
<xsl:with-param name="nodes"
select="$nodes[position() != $thisPosition]"/>
<xsl:with-param name="current" select="concat($current, .)"/>
</xsl:call-template>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
The result of the transformation, when applied to your xml source is:
ABH;AHB;BAH;BHA;HAB;HBA;
Hope this helped.
Cheers,
Dimitre Novatchev.
Cihan.Uslu@med.ge.com wrote:
Is it possible to get all the answers' item-ids in a way that covers
all the possible correct answer combination.
For example I have this multiple choice question in XML and the correct
answers are "A" "B" and "H".
What I want to output is to get all the possible correct answer
combination like this:
"ABH | AHB | BAH | BHA | HAB | HBA"
How can I do this in XSL?
Thanks.
Cihan
<assessment teds-type="M" required="Y" critical="N">
<question>
<stem>
<para>This is the third question.</para>
</stem>
<answer item-id="A">
<para>This is the answer.</para>
</answer>
<answer item-id="B">
<para>This is a answer.</para>
</answer>
<distractor item-id="C">
<para>This is a wrong answer.</para>
</distractor>
<distractor item-id="D">
<para>This is a wrong answer.</para>
</distractor>
<distractor item-id="E">
<para>This is a wrong answer.</para>
</distractor>
<distractor item-id="F">
<para>This is a wrong answer.</para>
</distractor>
<distractor item-id="G">
<para>This is a wrong answer.</para>
</distractor>
<answer item-id="H">
<para>This is the right answer</para>
</answer>
<distractor item-id="I">
<para>This is a wrong answer.</para>
</distractor>
</question>
</assessment>
__________________________________________________
Do You Yahoo!?
Listen to your Yahoo! Mail messages from any phone.
http://phone.yahoo.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list