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

embedded stylesheets (long post contains code)

Subject: embedded stylesheets (long post contains code)
From: "Chris Pearson" <chrisp@xxxxxxxxxxx>
Date: Tue, 15 Jan 2002 11:32:18 -0500
embedded xslt stylesheet
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


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.