Don't display table part if element not present ????

P

Patrick

Hello and please forgive my newbieness,

Say I have one section of xml like this with 3 elements and the
following has 4 elements;

<deploy_info>
<datatype1>ADCP Velocity measurements</datatype1>
<datatype2>ADCP Temperature</datatype2>
<datatype3>ADCP Performance Data</datatype3>
</deploy_info>
<deploy_info>
<datatype1>ADCP Velocity measurements</datatype1>
<datatype2>ADCP Temperature</datatype2>
<datatype3>ADCP Performance Data</datatype3>
<datatype4>Seabird Microcat Data</datatype4>
<deploy_info>

And I have a table like such;

<table>
<tr>
<td><xsl:value-of select="datatype1"/></td>
</tr>
<tr>
<td><xsl:value-of select="datatype2"/></td>
</tr>
<tr>
<td><xsl:value-of select="datatype3"/></td>
</tr>
<tr>
<td><xsl:value-of select="datatype4"/></td>
</tr>
</table>

Assuming I already know how to do the xsl:for-each. How or can I even
tell xsl to not display the <tr> through </tr> for <datatype4> if it is
the first group that is selected for writing?

Thanks for any ideas on this,
Patrick

--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group – USF - College of Marine Science
http://ocgweb.marine.usf.edu Phone: 727 553-3334

The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld
 
M

Martin Honnen

Patrick said:
<deploy_info>
<datatype1>ADCP Velocity measurements</datatype1>
<datatype2>ADCP Temperature</datatype2>
<datatype3>ADCP Performance Data</datatype3>
</deploy_info>
<deploy_info>
<datatype1>ADCP Velocity measurements</datatype1>
<datatype2>ADCP Temperature</datatype2>
<datatype3>ADCP Performance Data</datatype3>
<datatype4>Seabird Microcat Data</datatype4>
<deploy_info>

And I have a table like such;

<table>
<tr>
<td><xsl:value-of select="datatype1"/></td>
</tr>
<tr>
<td><xsl:value-of select="datatype2"/></td>
</tr>
<tr>
<td><xsl:value-of select="datatype3"/></td>
</tr>
<tr>
<td><xsl:value-of select="datatype4"/></td>
</tr>
</table>

Assuming I already know how to do the xsl:for-each. How or can I even
tell xsl to not display the <tr> through </tr> for <datatype4> if it is
the first group that is selected for writing?

It might suffice to iterate over all child elements (XPath *) e.g.

<xsl:for-each select="deploy_info">
<table>
<tbody>
<xsl:for-each select="*">
<tr><td><xsl:value-of select="."/></td></tr>
</xsl:for-each>
</tbody>
</table>
</xsl:for-each>

Then there is xsl:if e.g.

<xsl:if test="datatype4">
<tr><td><xsl:value-of select="datatype4"/></td></tr>
</xsl:if>
 
P

Patrick

Martin said:
It might suffice to iterate over all child elements (XPath *) e.g.

<xsl:for-each select="deploy_info">
<table>
<tbody>
<xsl:for-each select="*">
<tr><td><xsl:value-of select="."/></td></tr>
</xsl:for-each>
</tbody>
</table>
</xsl:for-each>

Then there is xsl:if e.g.

<xsl:if test="datatype4">
<tr><td><xsl:value-of select="datatype4"/></td></tr>
</xsl:if>
Thanks for the pointer. That second one looks more intuitive to me. Is
there an advantage or disadvantage between the methods?

Patrick

--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group – USF - College of Marine Science
http://ocgweb.marine.usf.edu Phone: 727 553-3334

The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld
 
J

Joe Kesselman

the first group that is selected for writing?

I'm not entirely sure what that phrase is intended to mean in this
context. Could you give us a more specific example?
 
P

Patrick

Joe said:
I'm not entirely sure what that phrase is intended to mean in this
context. Could you give us a more specific example?
Joe,

Doesn't matter now. I got it to work using an "if test=" told to me by
another poster. Thanks for asking though. I have to work on my xml
vocabulary so I can more clearly explain myself.

Patrick

--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group – USF - College of Marine Science
http://ocgweb.marine.usf.edu Phone: 727 553-3334

The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld
 
J

Joseph Kesselman

Patrick said:
have to work on my xml
vocabulary so I can more clearly explain myself.

A useful technique is to include a (small!) specific example of what
you're starting with, what you want out -- and if you're asking for
debugging assistance -- a (small!) runnable stylesheet that demonstrates
the problem and its erroneous output. That way, if someone's confused by
the description they can look at the code.
 
P

Patrick

Joseph said:
A useful technique is to include a (small!) specific example of what
you're starting with, what you want out -- and if you're asking for
debugging assistance -- a (small!) runnable stylesheet that demonstrates
the problem and its erroneous output. That way, if someone's confused by
the description they can look at the code.

I'm pretty sure I did with the original post. But thanks for the reminder.

Patrick

--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group – USF - College of Marine Science
http://ocgweb.marine.usf.edu Phone: 727 553-3334

The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top