This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

embedded stylesheets (long post contains code)


hello list.

I'm trying to distribute a self-contained stylesheet to format and display data on MS IE 5.5 and higher browsers.  (I have to send a single file with an .xml extension)

I am able to generate my desired output with an external stylesheet call (e.g. <?xml-stylesheet type="text/xsl" href="style1.xsl"?> ) where I have one file of xml data and another file for my xslt stylesheet.  However, when I try to embed the stylesheet within the top-level element of my xml data, I no longer see the desired output (a formatted table with values).  I now see a sinlge line of all my node-text values, followed by my html structure (hr and a table hdr row.)

Can IE 5.5. and higher support embedded stylesheets?  What do I need to change in my stylesheet  to display correctly?

Thanks for any opinions / suggestions!
Chris

I'm changing these when I embed:
1) I'm adding a filter for the <xsl:stylesheet> nodes wth <xsl:template match="xsl:stylesheet" />
2) I'm changing the processing instruction from {href="style1.xsl"?>} to {href=}#style1"?>}
3) I'm inserting the stylesheet in between the last </body> closing tag and the </root> closing tag.

Sample XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="style1.xsl"?>
<root>
<header>
  <name>My Name</name>
</header>
<body>
  <part>Part A</part>
  <schedule>
    <date>Monday</date>
    <time>0900</time>
    <qty>5</qty>
  </schedule>
  <schedule>
    <date>Friday</date>
    <time>1400</time>
    <qty>10</qty>
  </schedule>
</body>
<body>
  <part>Part B</part>
  <schedule>
    <date>Monday</date>
    <time>0900</time>
    <qty>1</qty>
  </schedule>
</body>
</root>

My external stylesheet:
<xsl:stylesheet id="style1" version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:template match="/">
  <xsl:apply-templates select="//header"/>
</xsl:template>

<xsl:template match="header">
<html>
  <body>
    <xsl:variable name="count" select="1 + count(preceding::header1)" />
    <xsl:for-each select="//header">
      <xsl:call-template name="head">
        <xsl:with-param name="count" select="$count" />
      </xsl:call-template>
    </xsl:for-each>
  </body>
</html>
</xsl:template>

<xsl:template name="head">
  <xsl:param name="count" />
  <!-- first test if the body belongs with this header -->
  <xsl:if test="(1 + count(preceding-sibling::header))=$count">
    <h1><xsl:value-of select="name" /></h1>
    <hr/>
    <xsl:for-each select="following-sibling::body[count(preceding-sibling::header)=$count]">
        <xsl:call-template name="part" />
    </xsl:for-each>
  </xsl:if>
</xsl:template>

<xsl:template name="part">
  <h2><xsl:value-of select="part" /></h2>
  <h3>Schedule Detail</h3>  
  <table width='360' border='1'>
  <xsl:for-each select="schedule">
    <xsl:if test="position()=1">
    <tr>
      <td width='120' align='center' valign='bottom'><b>DAY</b></td>
      <td width='120' align='center' valign='bottom'><b>TIME</b></td>
      <td width='120' align='center' valign='bottom'><b>QUANTITY</b></td>
    </tr>
    </xsl:if>
    <xsl:call-template name="sched" />
  </xsl:for-each>
  </table>
</xsl:template>

<xsl:template name="sched">
    <tr>
      <td width='120' align='center' valign='bottom'>
        <xsl:value-of select="date" />
      </td>
      <td width='11%' align='center' valign='bottom'>
        <xsl:value-of select="time" />
      </td>
      <td width='11%' align='center' valign='bottom'>
        <xsl:value-of select="qty" />
      </td>
    </tr>
</xsl:template>
</xsl:stylesheet>

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]