Thx for the reply Swapna and Peter but with what you sent me i still
retrieve all the Questions with the coresponding answers..
I came up with an xslt that does what i want below:-
But i have a problem when i display it on the browser i get a BIG GAP between
The "HELLO" in the first row and the second ROW
Any advice on this..
Thanks alot
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<HTML>
<BODY>
<TABLE BORDER="1" width="800px" cellspacing="1" cellpadding="1">
<tr><td>hello</td></tr>
<xsl:for-each select="NSurveyVoter/Voter/Question/Answer">
<tr>
<td>
<xsl:value-of select="../Answer[Answer='<b>What dont you like about
working for CrazyJohns?</b>']/Answer/text()"/>
</td>
</tr>
<tr>
<td>
<xsl:value-of select="../Answer[Answer='<b>What dont you like about
working for CrazyJohns?</b>']/VoterAnswer"/>
</td>
</tr>
<tr>
<td>
<xsl:value-of select="../Answer[Answer='<b>What is the best thing
about working for Crazy Johns?</b>']/Answer/text()"/>
</td>
</tr>
<tr>
<td>
<xsl:value-of select="../Answer[Answer='<b>What is the best thing
about working for Crazy Johns?</b>']/VoterAnswer"/>
</td>
</tr>
<tr>
<td>
<xsl:value-of select="../Answer[Answer='<b>What improvements would
you like to see?(e.g Study support etc...)</b>']/Answer/text()"/>
</td>
</tr>
<tr>
<td>
<xsl:value-of select="../Answer[Answer='<b>What improvements would
you like to see?(e.g Study support etc...)</b>']/VoterAnswer"/>
</td>
</tr>
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
"swapna guddanti [MSFT]" wrote:
"Patrick.O.Ige" <Pa*********@discussions.microsoft.com> wrote in message
news:07**********************************@microsof t.com... Thanks for the reply Swapna..
And when i applied what you adviced i could loop through the Queations and
answer accordingly.
But what i want is match a particular question and answer e.g
<Answer><b>What improvements would you like to see?(e.g Study support
etc...)</b></Answer
I don't want to retrieve all the Questions and answer just the one above
or maybe any match i give to it.
Thanks
"swapna guddanti [MSFT]" wrote:
"Patrick.O.Ige" <pa********@optusnet.com.au> wrote in message
news:Ox**************@tk2msftngp13.phx.gbl...
> I have an xml and i'm trying to loop each node...
> When i do FOR EACH i seem not to get my desired result
> I want to loop through and get only the values that matches the question i > specified with the corresponding answers? I don't want to retrieve all the > Answer and VoteAnswers nodes
>
> <xsl:for-each select="NSurveyVoter/Voter/Question/Answer">
>
> <xsl:value-of select="Answer[Answer='</b>What dont you like
> about working for us?</b>']/Answer/text()"/>
>
> <xsl:value-of
> select="NSurveyVoter/Voter/Question/Answer[Answer='</b>What dont you
> like about working for us?</b>']/VoterAnswer"/>
>
> </xsl:for-each>
>
>
>
> But when i do :-
>
> <xsl:for-each select="NSurveyVoter/Voter/Question/Answer">
>
>
>
>
>
> <DIV STYLE="margin-left:1em">
>
> <tr>
>
> <td> <xsl:value-of select="Answer"/>
>
>
>
>
>
> </td>
>
> </tr>
>
>
>
> <tr>
>
> <td>
>
> <b>
>
> <xsl:value-of select="VoterAnswer"/>
>
>
>
> </b>
>
> </td>
>
> </tr>
>
>
>
>
>
> </DIV>
>
>
>
> </xsl:for-each>
>
> I get the result i want.
>
> What am i missing?
>
>
>
> My Xml below:-
>
> <?xml version="1.0" encoding="utf-8" ?>
>
> <?xml-stylesheet type="text/xsl" href="short.xsl"?>
>
> <NSurveyVoter>
>
>
>
> <Voter>
>
>
>
> <VoterID>649</VoterID>
>
> <SurveyID>13</SurveyID>
>
> <VoteDate>2005-09-29T12:38:12.9700000+10:00</VoteDate>
>
> <StartDate>2005-09-29T12:33:55.5330000+10:00</StartDate>
>
> <IPSource>192.168.100.77</IPSource>
>
> <Question>
>
> <QuestionText />
>
> <VoterID>649</VoterID>
>
> <QuestionId>574</QuestionId>
>
> <Answer>
>
> <AnswerID>2062</AnswerID>
>
> <Answer><b>What improvements would you like to see?(e.g Study support > etc...)</b></Answer>
>
> <VoterAnswer>higher sunday pay rates.</VoterAnswer>
>
> <VoterId>649</VoterId>
>
> <QuestionId>574</QuestionId>
>
> <SectionNumber>0</SectionNumber>
>
> </Answer>
>
> </Question>
>
>
>
> <Question>
>
> <QuestionText></QuestionText>
>
> <VoterID>649</VoterID>
>
> <QuestionId>575</QuestionId>
>
> <Answer>
>
> <AnswerID>2063</AnswerID>
>
> <Answer><b>What is the best thing about working for us?</b></Answer>
>
> <VoterAnswer>the relaxed friendly atmosphere.</VoterAnswer>
>
> <VoterId>649</VoterId>
>
> <QuestionId>575</QuestionId>
>
> <SectionNumber>0</SectionNumber>
>
> </Answer>
>
> </Question>
>
>
>
> <Question>
>
> <QuestionText></QuestionText>
>
> <VoterID>649</VoterID>
>
> <QuestionId>576</QuestionId>
>
> <Answer>
>
> <AnswerID>2064</AnswerID>
>
> <Answer></b>What dont you like about working for
> us?</b></Answer>
>
> <VoterAnswer>the product! very sick of telstra.</VoterAnswer>
>
> <VoterId>649</VoterId>
>
> <QuestionId>576</QuestionId>
>
> <SectionNumber>0</SectionNumber>
>
> </Answer>
>
> </Question>
>
> </Voter>
>
>
>
>
>
> </NSurveyVoter>
>
>
>
>
>
>
if you want to group the question and all the corresponding answers from
voters , then the following xslt might help.
you need to use a new template to loop over the answers for the particular question since the docuemnt order is always top down inside a template.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="//NSurveyVoter/Voter/Question/Answer/Answer">
<question>
<xsl:value-of select="."/>
<answers>
<xsl:call-template name="newTemplate">
<xsl:with-param name="question" select="."/>
</xsl:call-template>
</answers>
</question>
</xsl:for-each>
</xsl:template>
<xsl:template name="newTemplate">
<xsl:param name="question"/>
<xsl:for-each select="//NSurveyVoter/Voter/Question/Answer">
<answer>
<xsl:value-of select="VoterAnswer[../Answer = $question]"/>
</answer>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
hi,
If you want to group "a particular question" and the corresponding answers
then the following will do that.
Notice that I have used "normalize-space" function to take care of spaces in
hard coded strings.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="newTemplate">
<xsl:variable name="question" select="'What improvements would you like
to see?(e.g Study support
etc...)'"/>
<xsl:for-each select="//NSurveyVoter/Voter/Question/Answer">
<xsl:if test="normalize-space(VoterAnswer/../Answer) =
normalize-space($question)">
<answer>
<xsl:value-of select="VoterAnswer"/>
</answer>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
thanks,
swapna