[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Getting variable yet most immediate parentNode
XML= The general gist of the below application is to output a survey and all its questions, and give the user the appropriate options (answers). Problem: given the variable relationship between the <answer> nodes being matched and their parent <section>, how to reliably amtch the correct section @name? <root> <section key="A" name="Survey 1"> <answers> <options /> </answers> <questions> <answers /> <question> <answer> <option>True</option> <option>False</option> </answer> </question> </questions> </section> </root> XSL <xsl:template match="section"> <fieldset class="oneCol" id="{@key}"> <legend><span><xsl:value-of select="@name" /></span></legend> <xsl:apply-templates select="questions" /> </fieldset> </xsl:template> <xsl:template match="questions"> <xsl:apply-templates mode="q" select="option" /> <xsl:if test="following-sibling::questions"> <hr /> </xsl:if> </xsl:template> <xsl:template match="option" mode="q"> <div> <span class="two"> <label> <xsl:choose> <xsl:when test="@name"> <xsl:value-of select="@name"/> </xsl:when> <xsl:otherwise><xsl:value-of select="." /></xsl:otherwise> </xsl:choose> </label> </span> <xsl:choose> <xsl:when test="answers"> <xsl:apply-templates select="answers"> <xsl:with-param name="qKey" select="@key" /> </xsl:apply-templates> </xsl:when> <xsl:when test="../answers"> <xsl:apply-templates select="../answers"> <xsl:with-param name="qKey" select="@key" /> </xsl:apply-templates> </xsl:when> <xsl:when test="../../answers"> <xsl:apply-templates select="../../answers" > <xsl:with-param name="qKey" select="@key" /> </xsl:apply-templates> </xsl:when> <xsl:when test="../../../answers"> <xsl:apply-templates select="../../../answers" > <xsl:with-param name="qKey" select="@key" /> </xsl:apply-templates> </xsl:when> </xsl:choose> </div> </xsl:template> <xsl:template match="answers"> <xsl:param name="qKey" /> <xsl:if test="option"> <select> <option>Select one</option> <xsl:for-each select="option"> <option> <!-- [[ Need help below]] --> <xsl:if test="$R[section=current()/*/section/@key and questionKey=$qKey and (value=current()/@name or value=current()/.)]"> <xsl:attribute name="selected">selected</xsl:attribute> </xsl:if> <xsl:choose> <xsl:when test="@name"> <xsl:value-of select="@name"/> </xsl:when> <xsl:otherwise><xsl:value-of select="." /></xsl:otherwise> </xsl:choose> </option> </xsl:for-each> </select> <span class="print"> <xsl:value-of select="$R[section=current()/*/section/@key and question=$qKey and value=current()/@name or value=current()/.]/value"/> </span> </xsl:if> </xsl:template>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|