xsl-list
[Top] [All Lists]

Re: Multi-part search XPath expressions.

2004-09-11 07:47:57
For your original question, your select statement is correct, but you
can simplify it to this:

select="/Australian_Birds/Species[Extinct!="True" and Genus_Name="Alectura"]

Just like you had written out in plain English.

As for using the named template, in this case you could extract all
the common code within the same template, like this:

<p>
  <xsl:choose>
    <xsl:when test="Extinct='Yes' ">Extinct</xsl:when>
    <xsl:when test="Extinct='No' ">Living</xsl:when>
  <xsl:choose>
  <xsl:text> species name is </xsl:text>
  <xsl:value-of select="Common_Name"/>
</p>
(<i>
  <xsl:value-of select="Genus_Name"/>
  <xsl:text> </xsl:text>
  <xsl:value-of select="Species_Name"/>
</i>)

Josh

On Sat, 11 Sep 2004 14:50:19 +1000, David Adams <dpadams(_at_)gmail(_dot_)com> 
wrote:
You're going to be surprised how easy it is.
Right you are ;-) Thanks, that's a lot easier to read and write. I've
been experimenting with this and think something else may be coming
clear. The purpose of a select statements in apply-templates is to
select a set of nodes for processing, such as "select all extinct
birds":

       <xsl:apply-templates 
select='/Australian_Birds/Species[Extinct="Yes"]'/>

Then, the template can have whatever sorts of conditional behavior it
likes based on values within the nodes, such as:

<xsl:template match="Species">
  <xsl:choose>

    <xsl:when test="Extinct='Yes' ">
      <p>Extinct species name is <xsl:value-of select="Common_Name"/></p>
    </xsl:when>

        <xsl:when test="Extinct='No' ">
      <p>Living species name is <xsl:value-of select="Common_Name"/></p>
    </xsl:when>

    <xsl:otherwise></xsl:otherwise>
  </xsl:choose>
</xsl:template>

This, then, makes it easy to, for example, first list all extinct
species and then all living species:

<xsl:template match="Australian_Birds">
       <xsl:apply-templates 
select='/Australian_Birds/Species[Extinct="Yes"]'/>
       <xsl:apply-templates select='/Australian_Birds/Species[Extinct="No"]'/>
</xsl:template>

I'm still trying to get my head around the language and am now lead
into wondering about subroutines. If I expand the template to include,
for example, Genus and species name in italics, I end up with an
obvious redundancy:

 <xsl:when test="Extinct='Yes' ">
      <p>Extinct species name is <xsl:value-of select="Common_Name"/></p>
          (<i>
               <xsl:value-of select="Genus_Name"/>
           <xsl:text> </xsl:text>
           <xsl:value-of select="Species_Name"/>
               </i>)
    </xsl:when>

        <xsl:when test="Extinct='No' ">
      <p>Living species name is <xsl:value-of select="Common_Name"/></p>
                (<i>
               <xsl:value-of select="Genus_Name"/>
           <xsl:text> </xsl:text>
           <xsl:value-of select="Species_Name"/>
               </i>)
    </xsl:when>

Should I be looking at xsl:call-template to centralize, for example,
this section of the template?
             (<i>
                <xsl:value-of select="Genus_Name"/>
               <xsl:text> </xsl:text>
               <xsl:value-of select="Species_Name"/>
           </i>)

Thanks again,



---------------------------------------------
David Adams
 dpadams(_at_)gmail(_dot_)com
Bermagui 2546 NSW
---------------------------------------------

--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--