Re: [xsl] Passing Parameters or ?

Subject: Re: [xsl] Passing Parameters or ?
From: "Sean Melvin" <sempitt@xxxxxxxxxxx>
Date: Fri, 30 Mar 2001 16:06:10
This may be a little crude but it works. I'm not one who uses the "apply templates" very often.

Here's the stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>


<xsl:output method="html"/>
<xsl:variable name="totalB" select="count(test/a/b)"/>
<xsl:template match="test">
<html>
<body>
<table>
<tbody>
<xsl:for-each select="a">
<xsl:variable name="countB" select="count(b)"/>
<tr>
 <xsl:for-each select="b">
  <td>
   <xsl:attribute name="colspan">
    <xsl:value-of select="$totalB - $countB"/>
   </xsl:attribute>
   <xsl:value-of select="."/>
  </td>
 </xsl:for-each>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Here's the output:
<html>
<body>
<table>
<tbody>
<tr>
<td colspan="1">ab</td>
<td colspan="1">ab</td>
</tr>
<tr>
<td colspan="2">abcd</td>
</tr>
</tbody>
</table>
</body>
</html>

Hope this helps.
Sean Melvin


From: "David Morris" <dmorris@xxxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: [xsl] Passing Parameters or ?
Date: Wed, 28 Mar 2001 15:47:24 -0700

List members,

I am new to XSL so the following may seem trivial, but I could not find the answer in the
FAQ. How does one pre-process a document or node and then use the result in a
second pass? I assume this may require passing a parameter from one pass to
another, but I could not find an example that shows how to do this. I think this is
probably command and would come in handy to for calculating a percentage of total
or to set a column span (my case). Here is a sample of what I have been testing with:


<?xml version="1.0" encoding="UTF-8"?>
<test>
  <a>
    <b>ab</b>
    <b>ab</b>
  </a>
  <a>
    <b>abcd</b>
  </a>
</test>

Here is the style sheet:

<?xml version='1.0'?>

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

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

  <xsl:template match="test">
    <table><tbody>
      <xsl:apply-templates select="a" mode="pre"/>
      <xsl:apply-templates select="a" mode="process"/>
    </tbody></table>
  </xsl:template>

  <xsl:template match="a" mode="pre">
    <xsl:value-of select="count(*)" />
  </xsl:template>

  <xsl:template match="a" mode="process">
    <tr>
      <td>
        <xsl:value-of select="count(*)" />
      </td>
      <xsl:apply-templates />
    </tr>
  </xsl:template>

  <xsl:template match="b">
   <td>
      <xsl:apply-templates />
    </td>
  </xsl:template>

</xsl:stylesheet>

Here is what the output looks like:

<table>
<tbody>21<tr>
<td>2</td>
    <td>ab</td>
    <td>ab</td>

</tr>
<tr>
<td>1</td>
    <td>abcd</td>

</tr>
</tbody>
</table>

Which renders like:
21
2 ab     ab
1 abcd

The extra numbers in the output were just to prove that I had the necessary information
to do what I would like. What I would really like for output is:


<table>
<tbody>
<tr>
    <td>ab</td>
    <td>ab</td>
</tr>
<tr>
    <td colspan="2">abcd</td>
</tr>
</tbody>
</table>

I really appreciate any insight or suggestions and don't mind a response that just points to
an example or some documentation that I can understand (I didn't get very far with the
w3c recommendation).


Thanks,

David Morris


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



_________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com


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



Current Thread