How to select two attributes from the same node with one expression in XPath?
For example:
//person[@id='abc123']/@haircolor|/@weight"
PS. there are lots of "person" records
Try this:
//person[@id='abc123']/@*[name()='weight' or name()='haircolor']
If you're using an XPath 2.0 processor, you may also use a prettier option:
//person[@id='abc123']/(@haircolor|@weight)`
Are you wanting to search for person nodes based on the value of multiple attributes. If that's the question then you can just use ands e.g.
//person[@id='abc123' and @haircolor='blue' and @weight='...']
If you want to search on a single attribute, but return the values of the other attributes, I would do something like this:
<xsl:template match="person[@id='abc123']">
<xsl:value-of select="@haircolor"/>
<xsl:value-of select="@weight"/>
</xsl:template>
If you are trying to get the values of the specified attributes I would suggest introducing a variable for the requested person.
<xsl:variable name="person" select="//person[@id = 'abc123']" />
After that you can get any attribute from the requested person by using the specified variable.
<xsl:value-of select="$person/@haircolor" />
<xsl:value-of select="$person/@weight" />