xsl-list
[Top] [All Lists]

RE: [xsl] Document function (was Getting an error with a variable)

2006-07-29 02:26:55
This is a snippet of code. Am I on the right 
track or is there a more efficient way?

  <xsl:for-each
select="/legs/competition/leg/Competitor[../../@name=$paramVal1]">
  <tr>
    <td><xsl:value-of select="@no"/></td>
      <xsl:variable name="cNum">
          <xsl:value-of select="@no"/>
      </xsl:variable>

Never do this. Write

<xsl:variable name="cNum" select="@no"/>

There's no need to construct a new result tree fragment when you only want a
reference to a node. (And no need for three lines of code when one would do
- XSLT is verbose enough without making it worse).

    <td><xsl:value-of
select="document('EntryList.xml')/entrylist/competition/entry/
@driverSurname
[../@no=$cNum]"/>
    <td><xsl:value-of
select="document('EntryList.xml')/entrylist/competition/entry/
@coDriverSurna
me[../@no=$cNum]"/>

You're less reliant on the optimizer if you define a variable:

<xsl:variable name="entry" 
 
select="document('EntryList.xml')/entrylist/competition/entry[(_at_)no=$cNum]"/>

then select="$entry/@driverSurname" and select="$entry/@codriverSurname"

Note also, predicates can appear on steps in a path expression other than
the last. You can write

document('EntryList.xml')/entrylist/competition/entry[(_at_)no=$cNum]/@driverSurn
ame

Michael Kay
http://www.saxonica.com/


--~------------------------------------------------------------------
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>
--~--