Hi,
I'm a newbie to XSL, so was hoping that somebody could easily see the answer to this:
I am trying to write an XSL style sheet to build an html dropdown list. The list contains simple name-value pairs. The only extra requirement i have is to set one of the options to be 'selected' based on an attribute further up the tree.
this is the xml fragment:
<MetricGroup>
<MetricTargets SelectedMetric="26">
<MetricTarget>
<MetricTargetID>25</MetricTargetID>
<Name>100M</Name>
</MetricTarget>
<MetricTarget>
<MetricTargetID>26</MetricTargetID>
<Name>50M</Name>
</MetricTarget>
</MetricTargets>
</MetricGroup>
As you can see, there are two MetricTargets that I want to list in my drop down. I want to set the 2nd dropdown to be selected. This is my XSL code:
<xsl:element name="Select">
<xsl:attribute name="id">myDropDown</xsl:attribute>
<xsl:for-each select="MetricGroup/MetricTargets/MetricTarget">
<xsl:element name="Option">
<xsl:attribute name="value">
<xsl:value-of select="MetricTargetID"/>
</xsl:attribute>
<xsl:value-of select="Name"/>
<xsl:if test="MetricTargetID = ../@SelectedMetric">
<xsl:attribute name="selected"/>
</xsl:if>
</xsl:element>
</xsl:for-each>
</xsl:element>
I am stuck with how to compare the value of the MetricTargetID to the value of the SelectedMetric attribute. I know I need to use an IF statement to compare them, but I am unsure of how to get the SelectedMetric based on the current context.
Any ideas are appreciated.
MrPeds
I'm a newbie to XSL, so was hoping that somebody could easily see the answer to this:
I am trying to write an XSL style sheet to build an html dropdown list. The list contains simple name-value pairs. The only extra requirement i have is to set one of the options to be 'selected' based on an attribute further up the tree.
this is the xml fragment:
<MetricGroup>
<MetricTargets SelectedMetric="26">
<MetricTarget>
<MetricTargetID>25</MetricTargetID>
<Name>100M</Name>
</MetricTarget>
<MetricTarget>
<MetricTargetID>26</MetricTargetID>
<Name>50M</Name>
</MetricTarget>
</MetricTargets>
</MetricGroup>
As you can see, there are two MetricTargets that I want to list in my drop down. I want to set the 2nd dropdown to be selected. This is my XSL code:
<xsl:element name="Select">
<xsl:attribute name="id">myDropDown</xsl:attribute>
<xsl:for-each select="MetricGroup/MetricTargets/MetricTarget">
<xsl:element name="Option">
<xsl:attribute name="value">
<xsl:value-of select="MetricTargetID"/>
</xsl:attribute>
<xsl:value-of select="Name"/>
<xsl:if test="MetricTargetID = ../@SelectedMetric">
<xsl:attribute name="selected"/>
</xsl:if>
</xsl:element>
</xsl:for-each>
</xsl:element>
I am stuck with how to compare the value of the MetricTargetID to the value of the SelectedMetric attribute. I know I need to use an IF statement to compare them, but I am unsure of how to get the SelectedMetric based on the current context.
Any ideas are appreciated.
MrPeds