Re: [xsl] xsl:variable

Subject: Re: [xsl] xsl:variable
From: Mike Brown <mike@xxxxxxxx>
Date: Mon, 10 Mar 2003 11:05:33 -0700 (MST)
Laurence Mossuz wrote:
> a part of my xml file looks like that :
> - <xsl:for-each select="toto">
> - <tr>
>   <xsl:apply-templates select="titi" />
>   <xsl:apply-templates select="tata" />
>   </tr>
>   </xsl:for-each>

That's not your XML.

Show us the XML you have, and the output you want to produce.

I *think* you are saying you have something like
<test>
  <toto>
    <titi>ti1</titi>
    <tata>ta1</tata>
  </toto>
  <toto>
    <titi>ti2</titi>
  </toto>
  <toto>
    <tata>ta3</titi>
  </toto>
  <toto/>
</test>

where each toto represents a table row, and where titi or tata may be missing.
When titi or tata are present, you want their value in the cell; otherwise you
want an HTML input element. Is this correct? I mean, is this the output you
would want?

<tr>
  <td>ta1</td>
  <td>ti1</td>
</tr>
<tr>
  <td>ta2</td>
  <td><input name="titi2" type="text" /></td>
</tr>
<tr>
  <td><input name="tata3" type="text" /></td>
  <td>ti3</td>
</tr>
<tr>
  <td><input name="tata4" type="text" /></td>
  <td><input name="titi4" type="text" /></td>
</tr>

If so, then when processing each toto, you can use its
position relative to all the totos selected for processing
as your counter.

<xsl:for-each select="toto">
  <tr>
    <td>
      <xsl:choose>
        <xsl:when test="string(tata)">
          <xsl:value-of select="tata"/>
        </xsl:when>
        <xsl:otherwise>
          <input name="tata{position()}" type="text"/>
        </xsl:otherwise>
      </xsl:choose>
    </td>
    <td>
      <xsl:choose>
        <xsl:when test="string(titi)">
          <xsl:value-of select="titi"/>
        </xsl:when>
        <xsl:otherwise>
          <input name="titi{position()}" type="text"/>
        </xsl:otherwise>
      </xsl:choose>
    </td>
  </tr>
</xsl:for-each>

If this is not exactly what you want, perhaps it at least gives you some
ideas.

Mike

-- 
  Mike J. Brown   |  http://skew.org/~mike/resume/
  Denver, CO, USA |  http://skew.org/xml/

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


Current Thread