XMl & XSL problem

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

XMl & XSL problem

Post by pickle »

Hi all,

I'm having trouble getting my XSL to 'style' my XML properly. Firefox loads the XSL file, but doesn't apply the variables properly. IE doesn't even load the XSL - just gives me it's rendering of the XML document.

A sampling of the XML document:

Code: Select all

<?xml version = "1.0" encoding = "ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href = "https://path/to/my/xsl/file" ?>
<picker>
  <square>
    <row>
      <colour red = "00" green = "ff" blue = "ff">
      </colour>
      <colour red = "00" green = "ff" blue = "ee">
      </colour>
      <colour red = "00" green = "ff" blue = "dd">
      </colour>
      <colour red = "00" green = "ff" blue = "cc">
      </colour>
    </row>
  </square>
</picker>
The result of my XSL transforming *should* be:

Code: Select all

<table>
  <tr>
    <td class = 'colourCell' style = "background-color:#00ffff;">
    </td>
    <td class = 'colourCell' style = "background-color:#00ffee;">
    </td>
    <td class = 'colourCell' style = "background-color:#00ffdd;">
    </td>
    <td class = 'colourCell' style = "background-color:#00ffcc;">
    </td>
  </tr>
</table>
...but as I said, in Firefox, the output is:

Code: Select all

<table>
  <tr>
    <td class = 'colourCell' style = "">
    </td>
    <td class = 'colourCell' style = "">
    </td>
    <td class = 'colourCell' style = "">
    </td>
    <td class = 'colourCell' style = "">
    </td>
  </tr>
</table>
The relevant XSL is:

Code: Select all

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
  <xsl:template match="/">     
    ...
     <body>
        <div style = "font-size:5pt;" onmouseover = 'showColour(event);' onclick = 'setColour(event);'>
          <xsl:for-each select="picker/square">
            <table cellspacing = "0" cellpadding = "0" border = "0" style = "display:inline;">
              <xsl:for-each select = "row">
                <tr>
                  <xsl:apply-templates />
                </tr>
              </xsl:for-each>
            </table>
            <xsl:if test="@newline='true'">
              <br />
            </xsl:if>
          </xsl:for-each>
          <div style = "border:1px solid #333;height:32px;width:152px;padding:3px;">
            <div id = "well" style = "font-family:Verdana,sans-serif;font-size:8pt;height:32px;width:152px;">
            </div>
          </div>
        </div>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="colour">
    <xsl:variable name="loopRed" select="@red" />
    <xsl:variable name="loopGreen" select="@green" />
    <xsl:variable name="loopBlue" select="@blue" />
    <td>
      <xsl:attribute name = "style">
        <xsl:text>
          background-color:#
        </xsl:text>
        <xsl:value-of select="$loopRed" />
        <xsl:value-of select="$loopGreen" />
        <xsl:value-of select="$loopBlue" />
      </xsl:attribute>
      <xsl:attribute name = "class">
        <xsl:text>
          colourCell
        </xsl:text>
      </xsl:attribute>
    </td>
  </xsl:template>
</xsl:stylesheet>
Can anyone see where I'm breaking?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply