0

i have an evaluation form filled in by a lot of users. i created an export in excel for this form. What i want to achieve is: the header of the excel will have all the questions and below every question the answers grouped by the user who filled in the form. For this, i'm getting the questions by evaluation form and order them by position, then i'm grouping the users who filled in the form, looping through the results of the grouping so i will have the same lines for every question. this is a part of the xml i'm generating:

<QUESTIONNAMES>
    <ITEM>
      <QUESID>468</QUESID>
      <QUESNAME><![CDATA[Name]]></QUESNAME>
    </ITEM>
    <ITEM>
      <QUESID>554</QUESID>
      <QUESNAME><![CDATA[Palce]]></QUESNAME>
    </ITEM>
</QUESTIONNAMES>
<EXPORTLINE>
      <ITEMS>
        <ITEM>
          <QUESID>468</QUESID>
          <VALUES>
            <UserID>25151</UserID>
            <VALUE><![CDATA[dommel]]></VALUE>
            <UserID>45372</UserID>
            <VALUE><![CDATA[Omnium]]></VALUE>
            <UserID>54632</UserID>
            <VALUE><![CDATA[Het Zand]]></VALUE>
            <UserID>56604</UserID>
            <VALUE><![CDATA[rijen]]></VALUE>
            <UserID>57103</UserID>
            <VALUE><![CDATA[Schanswiel]]></VALUE>
            ------  
           </VALUES>
        </ITEM>
      </ITEMS>
</EXPORTLINE>
 <EXPORTLINE>
      <ITEMS>
        <ITEM>
          <QUESID>554</QUESID>
          <VALUES>
            <UserID>22523</UserID>
            <VALUE><![CDATA[test,test]]></VALUE>
            <UserID>44308</UserID>
            <VALUE><![CDATA[Ede]]></VALUE>
            <UserID>47850</UserID>
            <VALUE><![CDATA[Drachten]]></VALUE>
            <UserID>50156</UserID>
            <VALUE><![CDATA[Dalfsen]]></VALUE>
            <UserID>50656</UserID>
            <VALUE><![CDATA[Dongen]]></VALUE>
            -----   
           </VALUES>
        </ITEM>
      </ITEMS>
</EXPORTLINE>

this is my xslt part:

<xsl:template name="enquteQuestions">
 <tr> 
    <xsl:for-each select="QUESTIONNAMES/ITEM">
        <td align="left"><xsl:value-of select="QUESNAME" /></td>
    </xsl:for-each>  
 </tr>
 <tr>
    <xsl:for-each select="QUESTIONNAMES/ITEM">
        <xsl:variable name="quesid" select="QUESID" /> 
        <td align="left">   
            <xsl:for-each select="EXPORTLINE/ITEMS/ITEM[QUESID=$quesid]/VALUES/VALUE">
                 <xsl:sort select="VALUE"/>
                <xsl:value-of disable-output-escaping="yes" select="." /><br />
            </xsl:for-each>         
        </td>
    </xsl:for-each> 
</tr>

The problem is that: in the excel file, the answers are not matched, what i mean is that the answers of the second question do not match the answers of the first.

now i have:

Name           |Place
--------------------------
dommel         | test, test ----> i need to make sure that the answers of the second question match the answer of the first question.

let me know if it is not clear and if you have any suggestions to solve this.

thanks in advance.

2
  • Not entirely clear... what do you mean by "match" in "the answers of the second question do not match the answers of the first"? Your sample output seems to show the first answer to the first question, and the first answer to the second question, on the same line, under the appropriate question names. What was the output you expected? Commented Nov 15, 2010 at 11:45
  • Also, I question whether you really want to use disable-output-escaping, but that's probably a separate issue. Commented Nov 15, 2010 at 11:47

3 Answers 3

1

In your for-each the context node is a VALUE element thus the xsl: sort should simply do select=".".

Sign up to request clarification or add additional context in comments.

Comments

0

thanks to all of you for your remakrs and answers. it was something in the structure of the xml, i was quering on the answers by question vertically and if the user did not fill something fo a question then the order is getting missed up and the answers by question are not grouped by user anymore, so you can have answer of the second question for a user but the answer of the third question for another user and not the same one. now i catch also the questions that the user did not fill in. this way i will have the same results and the same order for all the questiosn and the appropriate answers by user.

thanks again.

1 Comment

This should go in question, not as answer.
0

This is like a CVS output when you don't know if there is missing fields (Users answers in this case). So, this stylesheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:key name="kUserIDByValue" match="UserID" use="."/>
    <xsl:key name="kValueByQuestion-User" match="VALUE"
             use="concat(../../QUESID,'++',preceding-sibling::UserID[1])"/>
    <xsl:variable name="vQuestions" select="/*/QUESTIONNAMES/ITEM/QUESID"/>
    <xsl:template match="text()"/>
    <xsl:template match="/">
        <table>
            <xsl:apply-templates/>
        </table>
    </xsl:template>
    <xsl:template match="QUESTIONNAMES">
        <tr>
            <xsl:apply-templates/>
        </tr>
    </xsl:template>
    <xsl:template match="QUESNAME">
        <td>
            <xsl:value-of select="."/>
        </td>
    </xsl:template>
    <xsl:template match="UserID[count(.|key('kUserIDByValue',.)[1])=1]">
        <tr>
            <xsl:apply-templates select="$vQuestions" mode="output">
                <xsl:with-param name="pUserId" select="."/>
            </xsl:apply-templates>
        </tr>
    </xsl:template>
    <xsl:template match="QUESID" mode="output">
        <xsl:param name="pUserId"/>
        <td>
            <xsl:value-of select="key('kValueByQuestion-User',
                                      concat(.,'++',$pUserId))"/>
        </td>
    </xsl:template>
</xsl:stylesheet>

Output:

<table>
    <tr>
        <td>Name</td>
        <td>Palce</td>
    </tr>
    <tr>
        <td>dommel</td>
        <td></td>
    </tr>
    <tr>
        <td>Omnium</td>
        <td></td>
    </tr>
    <tr>
        <td>Het Zand</td>
        <td></td>
    </tr>
    <tr>
        <td>rijen</td>
        <td></td>
    </tr>
    <tr>
        <td>Schanswiel</td>
        <td></td>
    </tr>
    <tr>
        <td></td>
        <td>test,test</td>
    </tr>
    <tr>
        <td></td>
        <td>Ede</td>
    </tr>
    <tr>
        <td></td>
        <td>Drachten</td>
    </tr>
    <tr>
        <td></td>
        <td>Dalfsen</td>
    </tr>
    <tr>
        <td></td>
        <td>Dongen</td>
    </tr>
</table>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.