tags:

views:

122

answers:

2

I need to get the value of the 'test' attribute in the xsl:when tag, and the 'name' attribute in the xsl:call-template tag. This xpath gets me pretty close:

..../xsl:template/xsl:choose/xsl:when

But that just returns the 'when' elements, not the exact attribute values I need.

Here is a snippet of my XML:

<xsl:template match="field">
    <xsl:choose>
    <xsl:when test="@name='First Name'">
        <xsl:call-template name="handleColumn_1" /> 
    </xsl:when>
</xsl:choose>
+2  A: 

do you want .../xsl:template/xsl:choose/xsl:when/@test

If you want to actually get the value 'First Name' out of the test attribute, you're out of luck -- the content inside the attribute is just a string, and not a piece of xml, so you can't xpath it. If you need to get that, you must use string manipulation (Eg, substring) to get the right content

Steve Cooper
Yes thats exactly what I'm looking for, and I know I can't parse out the @name= value, I can do that after I get the data back from my xpath operation.What about getting the name value from the call-template?thank you!
Actually I need to end up having the "handleColumn_1" value somehow associated with the "@name='First Name'" value... so if there is anything that will get me closer to that, that would be great.
+1  A: 

Steve Cooper answered the first part. For the second part, you can use:

.../xsl:template/xsl:choose/xsl:when[@test="@name='First Name'"]/xsl:call-template/@name

Which will match specifically the xsl:when in your above snippet. If you want it to match generally, then you can use:

.../xsl:template/xsl:choose/xsl:when/xsl:call-template/@name
fd