[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

node-set processing

Subject: node-set processing
From: Kamal Bhatt <kbhatt@xxxxxxxxx>
Date: Mon, 05 Dec 2005 10:20:35 +1100
cell pad
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.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.