xsl-list
[Top] [All Lists]

Re: Multi-part search XPath expressions.

2004-09-10 18:04:57

On Sep 10, 2004, at 8:36 PM, David Adams wrote:

I want to do searches, such as

     select species where the Extinct="True" and Genus_Name="Alectura"

The best I've been able to come up with is an expression like the one below:

/Australian_Birds/Species[Extinct!="True"]/self:: Species[Genus_Name="Alectura"]

You're going to be surprised how easy it is.

Say you do a template match on Species. Your select or test xpath statement is then "Extinct='True' and Genus_Name='Alectura'".

So, put it all together and you might have:

<xsl:template match="/">
  <h1>Birds</h1>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="Species">
  <xsl:choose>
    <xsl:when test="Extinct='False' and Genus_Name='Casuarius'">
      <p>species name is <xsl:value-of select="Species_Name"/></p>
    </xsl:when>
    <xsl:otherwise></xsl:otherwise>
  </xsl:choose>
</xsl:template>

Bruce