Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: XSL Test expression: please help >Thread Next - Re: XSL Test expression: please help Re: XSL Test expression: please helpTo: NULL Date: 7/7/2006 5:50:00 AM
Thanks, George! That seems to do the trick.
I guess I'm fairly new to XSL, so the way you're setting the
showQuestion variable is new to me. Thanks for the tip.
Moskie
George Bina wrote:
> Hi,
>
> You need to iterate on the triggers for a questions and check each
> trigger condition:
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:key name="tr" match="Trigger" use="QuestionID"/>
> <xsl:key name="q" match="Question" use="QuestionID"/>
> <xsl:template match="/*">
> <xsl:copy>
> <xsl:for-each select="Question">
> <xsl:variable name="triggers" select="key('tr', QuestionID)"/>
> <xsl:variable name="showQuestion">
> <xsl:choose>
> <xsl:when test="count($triggers)=0">yes</xsl:when>
> <xsl:otherwise>
> <xsl:for-each select="$triggers">
> <xsl:if
> test="ParentValue=key('q',ParentQuestionID)/CurrentValue">yes</xsl:if>
> </xsl:for-each>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:variable>
> <xsl:if test="string-length($showQuestion)>0">
> <xsl:copy-of select="."/>
> </xsl:if>
> </xsl:for-each>
> </xsl:copy>
> </xsl:template>
> </xsl:stylesheet>
>
> Best Regards,
> George
> ---------------------------------------------------------------------
> George Cristian Bina
> <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
> www.---.com
>
>
> moskie@g... wrote:
> > I have some XML representing survey questions and answers, along with
> > "trigger" definitions that represent a signal for when certain
> > questions should be displayed. Here's a stripped down example:
> >
> > <Question>
> > <QuestionID>1</QuestionID>
> > <CurrentValue>0</CurrentValue>
> > </Question>
> > <Question>
> > <QuestionID>2</QuestoinID>
> > <CurrentValue>1</CurrentValue>
> > </Question>
> > <Question>
> > <QuestionID>3</QuestionID>
> > <CurrentValue>0</CurrentValue>
> > </Question>
> >
> > <Trigger>
> > <QuestionID>3</QuestionID>
> > <ParentQuestionID>1</ParentQuestionID>
> > <ParentValue>0</ParentValue>
> > </Trigger>
> > <Trigger>
> > <QuestionID>3</QuestionID>
> > <ParentQuestionID>2</ParentQuestionID>
> > <ParentValue>0</ParentValue>
> > </Trigger>
> >
> > Basically, those triggers say that Question 3 should be displayed when
> > either Question 1 has a value of 0, or when Question 2 has a value of
> > 0. I plan to loop through each question, then run a test expression
> > that will determine whether that particular question gets displayed.
> >
> > First, the easy part:I test to see if there are no triggers for a
> > question, meaning that the question should always be displayed:
> >
> > not(../Trigger[QuestionID = current()/QuestionID])
> >
> > The other part is where I'm stuck: testing to see if any of the
> > triggers' conditions have been met. This is what I have so far:
> >
> > or
> > ../Question[QuestionID = ../Trigger[QuestionID =
> > current()/QuestionID]/ParentQuestionID]/CurrentValue =
> > ../Trigger[QuestionID = current()/QuestionID]/ParentValue
> >
> > However, that just compares the set of CurrentValues of ParentQuestions
> > with the set of ParentValues from the all the Trigger nodes.... but
> > doesn't correlate the ParentQuestion and ParentAnswers together...
> >
> > Can anyone help me out in getting this expression to work?
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
