XSL:IF

LisaDi

Usenet Archive
Joined
Apr 20, 2002
Messages
2
Reaction score
0
Hi,
In my XML file, I have multiple 'Job' nodes. Within that node, there is an 'Award' item. Not every job has an 'Award' populated. :-(

When I output this in XSL, I would like to use an IF statement to only print the Award row if it's not blank. (I'd like to format this with a list item, and not have a list item display w/o any data by it.)

Can someone please point me in the direction of some tutorials/syntax help for this? I've seen a few snippets of code for checking for the position of an item, but not for if > 0.

Thanks!
Lisa

==== XML ====

<Job>
<Date_Worked>a</Date_Worked>
<Position_Title>b</Position_Title>
<Comp>
<Comp_Name>
<Comp_1>c</Comp_1>
<Comp_2>e</Comp_2>
</Comp_Name>
<Comp_City>Chicago</Comp_City>
<Comp_St>IL</Comp_St>
</Comp>
<Award>Employee of the Month</Award>
<Job_Desc>blah</Job_Desc>
</Job>

==== XSLT ====
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="Work_History">... .... .... .... <xsl:for-each select="Work_Exp/Job"> <tr> <td width="23%" colspan="2" valign="top" align="left"> <b><xsl:value-of select="Position_Title"/></b><br/> <xsl:value-of select="Date_Worked"/> </td> .... ....
....

<!-- NEED IF HERE -->
<tr><td width="100%" colspan="6" valign="top" align="left"> <xsl:value-of select="Award"/> </td> </tr>

</xsl:for-each>
 

Andy Fish

Usenet Archive
Joined
Dec 30, 2002
Messages
605
Reaction score
0
If I understand you correctly, it should be as simple as

<xsl:if test="Award">

Andy
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
LisaDi wrote:
Hi,
In my XML file, I have multiple 'Job' nodes. Within that node, there is an 'Award' item. Not every job has an 'Award' populated. :-(

When I output this in XSL, I would like to use an IF statement to only print the Award row if it's not blank. (I'd like to format this with a list item, and not have a list item display w/o any data by it.)

Can someone please point me in the direction of some tutorials/syntax help for this? I've seen a few snippets of code for checking for the position of an item, but not for if > 0.
Here is an example:

<?xml version="1.0" encoding="UTF-8"?>
<riders>
<rider>
<name>Lance Armstrong</name>
<award year="2002">Sportsman of the Year</award>
</rider>
<rider>
<name>Glance Legweak</name>
<award></award>
</rider>
</riders>

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

<xsl:eek:utput method="html" />

<xsl:template match="/">
<html>
<head>
<title>Riders</title>
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>

<xsl:template match="riders">
<ul>
<xsl:apply-templates />
</ul>
</xsl:template>

<xsl:template match="rider">
<li>
<xsl:value-of select="text" />
<xsl:apply-templates />
</li>
</xsl:template>

<xsl:template match="award">
<xsl:if test="node">
(Award: <xsl:value-of select="." />)
</xsl:if>
</xsl:template>

</xsl:stylesheet>

Thus the test to perform is whether an <award> element has any child node <xsl:if test="node"
 

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
548,208
Messages
3,104,798
Members
249,594
Latest member
henrywalsh

Latest Threads

Top