[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Formatting table information
Here is my code for the generation of tables:
<xsl:template match="Table"> <xsl:param name="title"/> <xsl:variable name="table-pos" select="position()"/> <xsl:text>&newln;</xsl:text> <xsl:variable name="length"> <xsl:call-template name="longest-str"> <xsl:with-param name="set" select="Row/Cell[1]"/> </xsl:call-template> </xsl:variable> <xsl:for-each select="Row"> <xsl:variable name="padded-cell"> <xsl:call-template name="append-pad"> <xsl:with-param name="pad-var" select="normalize-space(Cell[1])"/> <xsl:with-param name="length" select="$length"/> </xsl:call-template> </xsl:variable> <xsl:choose> <xsl:when test="position() = 1 and $table-pos = 1"> <!-- TEXT OUTPUT BEGINS --> <xsl:value-of select="$title"/>:<xsl:text>&tab;</xsl:text> <xsl:value-of select="$padded-cell"/> <xsl:text>&tab;</xsl:text> <xsl:value-of select="normalize-space(Cell[2])"/> <xsl:if test="position() != last()"> <xsl:text>&newln;</xsl:text> </xsl:if> <!-- TEXT OUTPUT ENDS --> </xsl:when> <xsl:otherwise> <!-- TEXT OUTPUT BEGINS --> <xsl:text>&tab;</xsl:text> <xsl:value-of select="$padded-cell"/> <xsl:text>&tab;</xsl:text> <xsl:value-of select="normalize-space(Cell[2])"/> <xsl:if test="position() != last()"> <xsl:text>&newln;</xsl:text> </xsl:if> <!-- TEXT OUTPUT ENDS --> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:template> <xsl:template name="longest-str"> <xsl:param name="set"/> <xsl:param name="curr-max-size" select="0"/> <xsl:param name="index" select="1"/> <xsl:variable name="curr-size" select="string-length($set[$index])"/> <xsl:choose> <xsl:when test="$index > count($set)"> <xsl:value-of select="$curr-max-size"/> </xsl:when> <xsl:when test="string-length($set[$index]) > $curr-max-size"> <xsl:call-template name="longest-str"> <xsl:with-param name="set" select="$set"/> <xsl:with-param name="index" select="$index + 1"/> <xsl:with-param name="curr-max-size" select="$curr-size"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:call-template name="longest-str"> <xsl:with-param name="set" select="$set"/> <xsl:with-param name="index" select="$index + 1"/> <xsl:with-param name="curr-max-size" select="$curr-max-size"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> <!-- Code taken from www.dpawson.co.uk/xsl/sect2/padding.html --> <xsl:template name="append-pad"> <xsl:param name="pad-char"><xsl:text>&space;</xsl:text></xsl:param> <xsl:param name="pad-var"/> <xsl:param name="length"/> <xsl:choose> <xsl:when test="string-length($pad-var) < $length"> <xsl:call-template name="append-pad"> <xsl:with-param name="pad-char" select="$pad-char"/> <xsl:with-param name="pad-var" select="concat($pad-var, $pad-char)"/> <xsl:with-param name="length" select="$length"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="substring($pad-var, 1, $length)"/> </xsl:otherwise> </xsl:choose> </xsl:template> Ragulf Pickaxe wrote: In a previous post I mentioned that that I have created a template to
|
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
|