SV: [thelist] XSL / XPath

Marcus Andersson marcan at home.se
Tue Nov 4 11:09:41 CST 2003


I provide an example below. A comment about your xpath question is
placed in your code.

/Marcus

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
  
  <xsl:template match="headline">
    <table border="1">      
      <!-- You want to get the two first elements. You can get the
position of the element
           with the position() xpath function and use it inside a
predicate rule. It starts at position 1
           so if you want the first two you select the ones with
position less than 3 -->
      <xsl:apply-templates select="furtherdetails/runner[position() &lt;
3]"/>
    </table>
  </xsl:template>
  
  <xsl:template match="runner">
    <tr>
      <td><xsl:value-of select="@id"/></td>
      <td><xsl:value-of select="@handicap"/></td>
      <td><xsl:value-of select="text()"/></td>
    </tr>
  </xsl:template>
  
</xsl:stylesheet>



-----Ursprungligt meddelande-----
Från: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org] För Drew Shiel
Skickat: den 4 november 2003 11:52
Till: thelist at lists.evolt.org
Ämne: [thelist] XSL / XPath



Here's a chunk of XML:

<headline>
         <furtherdetails>
                 <event id="248914" eventtypeid="94" betlive="0" 
bettingtype="Outright" numrunners="20">2003 World Cup - Outright</event>
                 <runner id="847157" handicap="0" currentprice="1.25" 
fractionprice="5/4 ">New Zealand</runner>
                 <runner id="847158" handicap="0" currentprice="1.5" 
fractionprice="3/2 ">England</runner>
                 <runner id="847159" handicap="0" currentprice="5" 
fractionprice="5/1 ">Australia</runner>
                 <runner id="847160" handicap="0" currentprice="12" 
fractionprice="12/1 ">France</runner>
         </furtherdetails>
</headline>

I'm trying to work out the XSL/XPath stuff to say "Take the first two 
runner nodes and do THIS with them", where THIS is dropping some of the 
values into a HTML table.

Anyone able to explain it? The XPath things have me baffled.

Drew.


Drew Shiel, Web Development, Sports Interaction
ashiel at sportsinteraction.com http://www.sportsinteraction.com/
+353-1-2365701 (Direct Line)

-- 
* * Please support the community that supports you.  * *
http://evolt.org/help_support_evolt/

For unsubscribe and other options, including the Tip Harvester 
and archives of thelist go to: http://lists.evolt.org 
Workers of the Web, evolt ! 



More information about the thelist mailing list