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]

Passing Parameters or ?


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


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