[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Need help with xsl:for-each and xsl:value-of

Subject: Need help with xsl:for-each and xsl:value-of
From: "Williams, Chris D." <WILLIC10@xxxxxxxxxxxxxxxxxx>
Date: Wed, 20 Mar 2002 13:02:22 -0800
xsl for each
I have a simple table I am trying to create.  Here is the sample XML file.

<?xml version="1.0" encoding="UTF-8"?>
<test>
  <item att1="foo1" att2="bar1"/>
  <item att2="bar2"/>
  <item att1="foo3"/>
  <item/>
  <item att1="foo5" att2="bar5"/>
</test>

I am currently using XMLSpy to create a XSL file to create my HTML table.
It does create a basic table but not exaclty what I want.  Right now, if
either att1 or att2 if not set, nothing gets placed in the table cell.  What
I would like to do it do a test of that value to see if it is defined and if
not, place some other fixed value there.  I have tried adding various if
conditions without any success.  Can this be done??  Should I use some other
command other that xsl:for-each?  Here is the stylesheet it is generating.

Thanks
Chris

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xsl:template match="/">
  <html>
    <head />
      <body>
        <xsl:for-each select="test">
          <xsl:for-each select="item">
            <xsl:if test="position()=1">
              <xsl:text disable-output-escaping="yes">&lt;table
border="1"&gt;</xsl:text>
            </xsl:if>
            <xsl:if test="position()=1">
              <thead>
                <tr>
                  <td>att1</td>
                  <td>att2</td>
                </tr>
              </thead>
            </xsl:if>
            <xsl:if test="position()=1">
              <xsl:text
disable-output-escaping="yes">&lt;tbody&gt;</xsl:text>
            </xsl:if>
            <tr>
              <td>
                <xsl:for-each select="@att1">
                  <xsl:value-of select="." />
                </xsl:for-each>
              </td>
              <td>
                <xsl:for-each select="@att2">
                  <xsl:value-of select="." />
                </xsl:for-each>
              </td>
            </tr>
            <xsl:if test="position()=last()">
              <xsl:text
disable-output-escaping="yes">&lt;/tbody&gt;</xsl:text>
            </xsl:if>
            <xsl:if test="position()=last()">
              <xsl:text
disable-output-escaping="yes">&lt;/table&gt;</xsl:text>
            </xsl:if>
          </xsl:for-each>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.