Abhinash Jha
Abhinash Jha

Reputation: 387

Where to find the attribute mentioned in xsl: value of tag

This is my first experience with xsl. I have a dropdown where I need to a new value. Till now I have figured out which attribute is used to populate the dropdown, but cannot find where the attribute is defined. Below is the section for dropdown.

<select id="idProgram" name="recog_cd" size="1">
   <!-- force default program to be listed first -->
   <xsl:for-each select="program">
      <xsl:if test="@recog_cd = $default_program_sel">
         <option value="{@recog_cd}">
            <xsl:choose>
               <xsl:when test="@recog_cd = $sel_recog_cd">
                  <xsl:attribute name="selected">yes</xsl:attribute>
               </xsl:when>
               <xsl:when test="@recog_cd = $input[@name='recog_cd']">
                  <xsl:attribute name="selected">yes</xsl:attribute>
               </xsl:when>
               <xsl:when test="@recog_cd = $default_program_sel">
                  <xsl:attribute name="selected">yes</xsl:attribute>
               </xsl:when>
            </xsl:choose>
            <xsl:value-of select="@name"/>
         </option>
      </xsl:if>
   </xsl:for-each>

What I want to know is where can "@name" be. As i understand, @ Selects attributes(from w3schools.com), but I don't find any attribute "name". So, for ex: default_program_sel above is defined as a variable as below:

<xsl:variable name="default_program_sel">
   <xsl:value-of select="../cis_page_header/@default_program_sel"/>
</xsl:variable>

I am able to find default_program_sel in a XMLPluginClass.

builder.addAttribute("default_program_sel", "CE");

I am looking for something similar for @name, but with no luck. Any help is appreciated.

Extra: If possible can someone let me know how can I print on page the result of sel_recog_cd(basically how to print any expression) ? I did -

Some value<xsl:value-of select="@sel_recog_cd" />

but only Some value was printed.

Thanks!

Upvotes: 0

Views: 74

Answers (1)

Conal Tuohy
Conal Tuohy

Reputation: 3258

In the statement

<xsl:value-of select="@name"/>

... the XPath expression @name is a "relative" XPath because it doesn't start with a / (the root of the document). So it's evaluated relative to a current node (called the "context node" in XPath).

So you will need to look for an XSLT statement which is an ancestor of this value-of statement, and which sets the context node. If you walk back up the tree from the value-of statement, looking for xsl: elements, you'll find a choose and an if (neither of which affect the context node) and finally a for-each (which does affect the context node):

<xsl:for-each select="program">
   ...
</xsl:for-each>

This for-each element has the effect of repeatedly executing its content nodes, each time with a different context node, drawn from the set of program elements. Note that the XPath expression program is also a relative XPath, but the context node in this case is determined by code which is outside of what you've posted in your question. You will need to walk back up the tree to find it, in the same way as I've explained for @name.

Upvotes: 1

Related Questions