xsl-list
[Top] [All Lists]

Re: Multi-part search XPath expressions.

2004-09-10 21:50:19
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
---------------------------------------------