|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] node-set processing
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 > $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 < 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 > $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 < 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.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








