[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Is this possible in XSL?

Subject: Re: Is this possible in XSL?
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Tue, 2 Oct 2001 21:38:14 -0700 (PDT)
combinations permutations xsl
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@xxxxxxxxxx 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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.