xsl-list
[Top] [All Lists]

Re: Trouble creating a table with multiple named templates

2005-05-03 09:23:16
Hi again Jay, 

I hope I am not keeping you from doing your real consulting work :),
thank you for the code below. It works as you said it would. I had
butchered some XSL to get that same result before but ran into the
problem of it not going through the entire XML tree. The same thing is
happening here except your code is much much better. I am able to have
it work through the tree when I just list an element by it's name and
do not use XPATH.

Example
<td><xsl:value-of select="fName"/></td>

Alas, that only works if I use an XPATH location in the match portion
of the template tag.

Example
<template match="directory/staffOffice/Office">

Then it will iterate through the entire tree for that portion. Is this
caused by having the extra node staffOffice? What is the next step I
should try?
Oh, and Boone as I am refering to it is a building at the location of
where I work.

Thanks again,

Max


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

  <xsl:template match="directory">
    <table>
      <tr>
        <td><xsl:value-of select="staffOffice/Office/dptFull"/></td>
      </tr>
      <tr>
        <td><xsl:value-of select="staffOffice/Office/Location"/></td>
        <td><xsl:value-of select="staffTitle/Position/phone"/></td>
        <!-- No fax or box in the sample, so skipped -->
      </tr>
      <tr>
        <td>
          <xsl:value-of
select="normalize-space(staffPersonal/Person/lName)"/>
          <xsl:text>, </xsl:text>
          <xsl:value-of
select="normalize-space(staffPersonal/Person/fName)"/>
        </td>
        <td><xsl:value-of select="staffTitle/Position/phone"/></td>
        <td><xsl:value-of select="staffTitle/Position/pEmail"/></td>
        <!-- No title in sample, so skipped -->
        <td><xsl:value-of select="staffOffice/Office/Location"/></td>
      </tr>
    </table>
  </xsl:template>

</xsl:stylesheet>

Produces this HTML fragment:

<table>
  <tr>
    <td>Biology</td>
  </tr>
  <tr>
    <td>Boone</td>
    <td>xxx-xxxx</td>
  </tr>
  <tr>
    <td>last Name, first Name</td>
    <td>xxx-xxxx</td>
    <td>xyxy(_at_)tttt(_dot_)com</td>
    <td>Boone</td>
  </tr>
</table>

I used the normalize-space function to remove the trailing spaces on the
names. Otherwise, I got a space before the comma.

I'm sure your data is more complex, but I hope this small stylesheet gives
you one idea for how to approach your problem. Other solutions exist.

If you run into trouble, let us know.

(That wouldn't be Boone, IA, would it?)

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)


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