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

Getting variable yet most immediate parentNode

Subject: Getting variable yet most immediate parentNode
From: Steve <subsume@xxxxxxxxx>
Date: Thu, 27 Sep 2007 14:55:15 -0400
 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>

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.