Thread: XSL problem

    #1
  1. a lazy guy
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    Hong Kong
    Posts
    99
    Rep Power
    13

    Question XSL problem


    Hello,

    I'm trying to use XSL to display different color in each row of the table. But the method I used below does not work. Any idea?

    (In HTML)
    <TABLE>
    <TR BGCOLOR="#FFFFFF"><TD>1</TD> ... <TR>
    <TR BGCOLOR="#AAAAAA"><TD>2</TD> ... </TR>
    <TR BGCOLOR="#FFFFFF"><TD>3</TD> ... </TR>
    <TR BGCOLOR="#AAAAAA"><TD>4</TD> ...</TR>
    </TABLE>

    (In XSL)
    <TABLE>
    <xsl:for-each select="./Atts/Att">
    <xsl:variable name="CHOOSE"><xsl:value-of select="position()"/></xsl:variable>
    <xsl:for-each select="./AttFormats/AttFormat">

    <tr>
    <xsl:choose>
    <xsl:when test="$CHOOSE mod 2 = 0">
    <xsl:attribute name="bgcolor">#FFFFFF</xsl:attribute>
    </xsl:when>
    <xsltherwise>
    <xsl:attribute name="bgcolor">#AAAAAA</xsl:attribute>
    </xsltherwise>
    </xsl:choose>
    <td><xsl:value-of select=".//somevalue"/></td>
    <td>...</td>
    </tr>
    </xsl:for-each>
    </xsl:for-each
    </TABLE>

    =================================
    The variable $CHOOSE seems NOT work with the function 'mod'.

    more info:
    The XML look like
    <Atts>
    <Att>
    <something></something>
    <AttFormats>
    <AttFormat>jpg</AttFormat>
    <AttFormat>gif</AttFormat>
    </AttFormats>
    </Att>
    <Att>
    ...
    ...
    </Att>
    </Atts>


    I need to display each file format (Attformat) in one row inside a table.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    France
    Posts
    2
    Rep Power
    0

    XSL Help to sunnychan


    I think you can try the following XSL stylesheet with your own XML document...
    (you must put "bgcolor" attribute into "td" tag only...)

    <!-- ************************************* -->
    <?xml version='1.0' encoding='iso-8859-1' ?>

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xslutput method="html" indent="yes" encoding="iso-8859-1" media-type="text/html"/>
    <!-- ************************************* -->

    <xsl:template match="Atts">
    <html>
    <head>
    </head>
    <body>
    <xsl:apply-templates/>
    </body>
    </html>
    </xsl:template>
    <!-- ************************************* -->
    <xsl:template match="Att">
    <table>
    <xsl:apply-templates select="AttFormats"/>
    </table>
    </xsl:template>
    <!-- ************************************* -->
    <xsl:template match="AttFormats">
    <xsl:for-each select="AttFormat">
    <xsl:variable name="CHOOSE" select="position()"/>
    <tr>
    <xsl:choose>
    <xsl:when test="$CHOOSE mod 2 = 0">
    <xsl:element name="td">
    <xsl:attribute name="bgcolor">#FFFFFF</xsl:attribute>
    <xsl:value-of select="$CHOOSE"/>
    </xsl:element>
    </xsl:when>
    <xsltherwise>
    <xsl:element name="td">
    <xsl:attribute name="bgcolor">#AAAAAA</xsl:attribute>
    <xsl:value-of select="$CHOOSE"/>
    </xsl:element>
    </xsltherwise>
    </xsl:choose>
    </tr>
    </xsl:for-each>
    </xsl:template>
    <!-- ************************************* -->

    </xsl:stylesheet>
    i hope it will work fine as you want



    Regards

    Analogx

    (don't hesitate to contact me if you need some help...)
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Posts
    1
    Rep Power
    0

    It's not the choose...


    We're using xalan (Java) to do XSLT. What we found out is that you can only set a xsl:variable ONCE. So when it's set once, it keeps that value. We work around it by determining the value elsewhere and passing it in through xslaram
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    France
    Posts
    2
    Rep Power
    0
    Hello

    I don't know Xalan.
    i'm using Sablotron with PHP.
    Sablotron is a XSLT Processor written in C++ (i think it's greter than Java :-)) ).

    For more informations i invite you to see Sablotron homepage
    http://www.gingerall.com

    Regards

    analogx

IMN logo majestic logo threadwatch logo seochat tools logo