xsl-list
[Top] [All Lists]

node-set processing

2005-12-04 16:20:35
Hi
I don't think I understand node-sets. What I want to do is create a generic function that will format tables up. To do this I have created a template that formats a table of the format

<Table>
   <Row>
         <Cell>Cell 1</Cell>
         <Cell>Cell 2</Cell>
   </Row>
   <Row>
          <Cell>This is the longest cell</Cell>
          <Cell>Cell 3<Cell>
   </Row>
</Table>

Formats to

Cell1                            Cell 2
This is the longest cell Cell 3
Or something to that effect.

Now I have already a template that finds the longest first Cell (which is necessary to pad out the cell), but this is far from generic. I have included this below:

<xsl:template name="cell-pad-size">
  <xsl:param name="curr-max-size"/>
  <xsl:param name="curr-node"/>

<xsl:variable name="curr-size" select="string-length(normalize-space(Row[position() = $curr-node]/Cell[1]))"/>
  <xsl:variable name="new-max-size">
      <xsl:choose>
       <xsl:when test="$curr-size &gt; $curr-max-size">
       <xsl:value-of select="$curr-size"/>
       </xsl:when>
       <xsl:otherwise>
       <xsl:value-of select="$curr-max-size"/>
       </xsl:otherwise>
   </xsl:choose>
  </xsl:variable>
  <xsl:choose>
   <xsl:when test="$curr-node &lt; count(Row)">
        <xsl:call-template name="locn-pad-size">
       <xsl:with-param name="curr-max-size"
               select="$new-max-size"/>
       <xsl:with-param name="curr-node" select="$curr-node + 1"/>
        </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
        <xsl:value-of select="$new-max-size"/>
   </xsl:otherwise>
  </xsl:choose>
</xsl:template>

Now, what I want is to create a template that will take a node set and return the longest value in the node set regardless of where it is. I created something like this:

<xsl:template name="cell-pad-size">
  <xsl:param name="curr-max-size"/>
  <xsl:param name="curr-node"/>
  <xsl:param name="node-set"/>

<xsl:variable name="curr-size" select="string-length(normalize-space(node-set[position() = $curr-node]))"/>
  <xsl:variable name="new-max-size">
      <xsl:choose>
       <xsl:when test="$curr-size &gt; $curr-max-size">
       <xsl:value-of select="$curr-size"/>
       </xsl:when>
       <xsl:otherwise>
       <xsl:value-of select="$curr-max-size"/>
       </xsl:otherwise>
   </xsl:choose>
  </xsl:variable>
  <xsl:choose>
   <xsl:when test="$curr-node &lt; count(node-set)">
        <xsl:call-template name="cell-pad-size">
       <xsl:with-param name="curr-max-size"
               select="$new-max-size"/>
       <xsl:with-param name="curr-node" select="$curr-node + 1"/>
        </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
        <xsl:value-of select="$new-max-size"/>
   </xsl:otherwise>
  </xsl:choose>
</xsl:template>

This template does nothing. I have a feeling that I am misunderstanding what can be done to a node set. For example, does a nodeset keep the position of the original source or will position give me the position in the node set? Can you even run position on a node-set?

Thanks.

Kamal.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>