Given this XML, is there an xpath that will give me the 'test' and 'name' values?

StackOverflow https://stackoverflow.com/questions/97474

  •  01-07-2019
  •  | 
  •  

Question

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>
Was it helpful?

Solution

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top