From: "Miguel" <[EMAIL PROTECTED]>
> > Can you be more specific ? I don't know much about JavaScript.
> > Can you give an exemple with what you want to put and what result you
> > expect ?
>
>I will use [square brackets] instead of <angle brackts>
>
> I want the ability to generate the following tag in the [header] section
>
> [script src="jmol/Jmol.js"][/script]
>
> I then need the ability to insert the following within the body:
>
> [script]
> arbitrary JavaScript code;
> [/script]

I have modified the xsl script to do something similar :

for the header part, just add an<html-head> tag in the <document>/<body>
part  with everything you want to see in the header (use <angle brackets>).

for the body part, just add your <script>...</script> in the document.

It should work but if not, just send me the xml file you want to parse, I
will work on it.

Nicolas
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">

  <xsl:output method="html" indent="yes"/>
  <xsl:param name="lang" select="'en'"/>
  <xsl:param name="project_xml" select="'project.xml'"/>
  
  <xsl:template match="document">
    <xsl:apply-templates/>
  </xsl:template>
  
  <xsl:template match="document/body">
    <xsl:if test="/document/properties/title">
      <br/>
      <h1><xsl:value-of select="/document/properties/title"/></h1>
    </xsl:if>
    <xsl:if test="header">
      <xsl:apply-templates select="header"/>
    </xsl:if>
    <xsl:variable name="numberOfSections" select="count(.//section)"/>
    <xsl:if test='$numberOfSections &gt; 1'>
    <xsl:for-each select=".//section">
      <small>
      <xsl:if test="@title">
        <xsl:variable name="level" select="count(ancestor::*)"/>
        <xsl:choose>
          <xsl:when test='$level=2'>
            <a href="[EMAIL PROTECTED]"><xsl:value-of select="@title"/></a><br/>
          </xsl:when>
          <xsl:when test='$level=3'>
            &#xA0;&#xA0;&#xA0;&#xA0;
            <a href="[EMAIL PROTECTED]"><xsl:value-of select="@title"/></a><br/>
          </xsl:when>
        </xsl:choose>
      </xsl:if>
      </small>
    </xsl:for-each>
    </xsl:if>
    <br/>
    <xsl:apply-templates select="section"/>
    <xsl:if test="footer">
      <br/>
      <xsl:apply-templates select="footer"/>
    </xsl:if>
  </xsl:template>


  <!-- Process a section in the document. Nested sections are supported -->
  <xsl:template match="document//section">
    <xsl:variable name="level" select="count(ancestor::*)"/>
    <xsl:choose>
      <xsl:when test='$level=2'>
        <a name="[EMAIL PROTECTED]"><h2><xsl:value-of select="@title"/></h2></a>
      </xsl:when>
      <xsl:when test='$level=3'>
        <a name="[EMAIL PROTECTED]"><h3><xsl:value-of select="@title"/></h3></a>
      </xsl:when>
      <xsl:when test='$level=4'>
        <a name="[EMAIL PROTECTED]"><h4><xsl:value-of select="@title"/></h4></a>
      </xsl:when>
      <xsl:when test='$level>=5'>
        <h5><xsl:copy-of select="@title"/></h5>
      </xsl:when>
    </xsl:choose>
    <blockquote>
      <xsl:apply-templates/>
    </blockquote>
  </xsl:template>

  <!-- Paragraphs are separated with one empty line -->
  <xsl:template match="p">
    <p><xsl:apply-templates/><br/></p>
  </xsl:template>

  <xsl:template match="url">
    <a href="{.}"><xsl:copy-of select="."/></a>
  </xsl:template>

  <xsl:template match="email">
    <a href="mailto:{.}";><xsl:copy-of select="."/></a>
  </xsl:template>

  <xsl:template match="html-head">
    <xsl:apply-templates/>
  </xsl:template>
  
  <xsl:template match="/">
    <xsl:variable name="project" select="document($project_xml)/project"/>
    <xsl:text disable-output-escaping="yes">&lt;html lang="</xsl:text>
    <xsl:value-of select="$lang" disable-output-escaping="yes"/>
    <xsl:text disable-output-escaping="yes">"&gt;</xsl:text>
    <head>
      <xsl:choose>
        <xsl:when test="/document/properties/title"><title><xsl:value-of select="/document/body/title"/></title></xsl:when>
        <xsl:when test="/document/body/title"><title><xsl:value-of select="/document/body/title"/></title></xsl:when>
        <xsl:otherwise><title><xsl:value-of select="$project/title"/></title></xsl:otherwise>
      </xsl:choose>
      <link rel="stylesheet" type="text/css" href="[root]/default.css"/>
      <xsl:apply-templates select="/document/body/html-head"/>
    </head>

    <body>
      <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
          <td valign="top">
            <xsl:apply-templates select="$project/links"/>
            <hr/>
          </td>
        </tr>

        <tr>
          <td>
            <h1>
              <xsl:choose>
                <xsl:when test="/document/body/title"><xsl:value-of select="/document/body/title"/></xsl:when>
                <xsl:otherwise><xsl:value-of select="$project/title"/></xsl:otherwise>
              </xsl:choose>
            </h1>
           </td>
        </tr>

        <tr>
          <td>
             <xsl:apply-templates select="document/body"/>
             <br/>
             <hr/>
          </td>
        </tr>

        <xsl:if test="$project/notice">
          <tr>
            <td align="center">
              <xsl:for-each select="$project/notice">
                <small><xsl:copy-of select="."/><br/>&#xA0;<br/></small>
              </xsl:for-each>
            </td>
          </tr>
        </xsl:if>

      </table>

    </body>
	<xsl:text disable-output-escaping="yes">&lt;/html&gt;</xsl:text>
  </xsl:template>


  <!-- UL is processed into a table using graphical bullets -->
<!--
  <xsl:template match="ul">
    <table border="0" cellpadding="2" cellspacing="2">
      <tr><td colspan="2" height="5"></td></tr>
      <xsl:apply-templates/>
    </table>
  </xsl:template>
-->

<!--
  <xsl:template match="ul/li">
    <tr>
      <td align="left" valign="top">
        <img src="images/blueball.gif" alt="*"/>
     </td>
      <td align="left" valign="top"><xsl:apply-templates/></td>
    </tr>
  </xsl:template>
-->

  <xsl:template match="screenshots">
    <table border="0" cellpadding="2" cellspacing="2">
      <tr><td colspan="2" height="5"></td></tr>
      <xsl:apply-templates/>
    </table>
  </xsl:template>
  
  <xsl:template match="screenshot">
    <tr>
      <td align="left" valign="middle">
        <a href="[EMAIL PROTECTED]">
        <img src="[EMAIL PROTECTED]" width="200" alt="Jmol screenshot"/>
        </a>
     </td>
      <td align="left" valign="middle"><xsl:apply-templates/></td>
    </tr>
  </xsl:template>

  <xsl:template match="appletParameterList">
    <table border="1" cellpadding="2" cellspacing="2">
      <tr>
        <th align="center" valign="middle">
        NAME=
       </th>
        <th align="center" valign="middle">VALUE=</th>
      </tr>
      <xsl:apply-templates/>
    </table>
  </xsl:template>
  
  <xsl:template match="appletParameterList/param">
    <tr>
      <td align="center" valign="top">
      <xsl:value-of select="@name"/>
     </td>
      <td align="left" valign="top"><xsl:apply-templates/></td>
    </tr>
  </xsl:template>

  <xsl:template match="section">
    <br />
  </xsl:template>

  <xsl:template match="br">
    <br />
  </xsl:template>

  <xsl:template match='@* | node()'>
    <xsl:copy>
      <xsl:apply-templates select='@* | node()'/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="appletExample">
    <pre>
    <xsl:value-of select='@* | node()'/>
    </pre>
    <xsl:value-of disable-output-escaping="yes" select='@* | node()'/>
  </xsl:template>


  <xsl:template match="contributors">
    <blockquote><xsl:text>
    </xsl:text>
    <xsl:for-each select="contributor" >
    <xsl:value-of select="name" />
    (<a href="mailto:{email}";><xsl:value-of select="email" /></a>)<br/><xsl:text>
    </xsl:text>
    </xsl:for-each>
    </blockquote>
  </xsl:template>

  <xsl:template match="changes">
    <h3><xsl:value-of select="@version" /></h3>
    <ul>
    <xsl:for-each select="change" >
      <li>
      <xsl:value-of select="." /><xsl:if test="@contributor"> (<xsl:value-of select="@
      contributor" />)</xsl:if>
      </li>
    </xsl:for-each>
    </ul>
  </xsl:template>

</xsl:stylesheet>


Reply via email to