[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Table type output in text fromat in a xml file
At 2007-12-27 00:45 -0800, rasha dwidar wrote:
Ken, I did something like that before but it lost the indentation as table format. Do u know how I can implement indentation or padding so I can have the same look and feel as table format. As If I have testcase name = test000000000000000001, I will lose the alignment in the table. I hope the example below helps. I try to do most of the indentation calculations in advance by loading up global variables with information that will be used when going through the data. I've also tried to accommodate the titles in the calculations in case the titles are longer than the data elements. . . . . . . . . . . Ken T:\ftemp>type rasha.xml <test> <testcase name="test001" result="failed" comment="test failed"/> <testcase name="test0000001" result="failed" comment="test failed"/> <testcase name="test001" result="passedxxxxxxx" comment="test passedxx"/> </test> T:\ftemp>type rasha.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="text"/> <xsl:variable name="titles" select="'Name','Result','Comment'"/> <xsl:variable name="maxes" select="max( for $each in ($titles[1],/*/testcase/@name) return string-length($each) ), max( for $each in ($titles[2],/*/testcase/@result) return string-length($each) ), max( for $each in ($titles[3],/*/testcase/@comment) return string-length($each) )"/> <xsl:variable name="pad" select="for $each in $maxes return string-join( for $repeat in 1 to $each return ' ','')"/> <xsl:template match="test"> <xsl:for-each select="$titles"> <xsl:call-template name="pad"/> </xsl:for-each> <xsl:text> </xsl:text> <xsl:apply-templates select="testcase"/> </xsl:template> <xsl:template match="testcase"> <xsl:apply-templates select="@name, @result, @comment"/> <xsl:text> </xsl:text> </xsl:template> <xsl:template match="@name | @result | @comment" name="pad"> <xsl:variable name="p" select="position()"/> <xsl:value-of select="."/> <xsl:value-of select="substring( $pad[$p], string-length(.) )"/> <xsl:text> </xsl:text> </xsl:template> </xsl:stylesheet> T:\ftemp>xslt2 rasha.xml rasha.xsl con Name Result Comment test001 failed test failed test0000001 failed test failed test001 passedxxxxxxx test passedxx T:\ftemp>
|
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
|