|
Subject: Re: [xsl] Table type output in text fromat in a xml file From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Thu, 27 Dec 2007 09:09:09 -0500 |
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.
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: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
-- Comprehensive in-depth XSLT2/XSL-FO1.1 classes: Austin TX,Jan-2008 World-wide corporate, govt. & user group XML, XSL and UBL training RSS feeds: publicly-available developer resources and training G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Table type output in text, Jesper Tverskov | Thread | [xsl] Replacing values in one xml f, Mujahid - E - Azam |
| Re: [xsl] xalan and replace "regex", Abel Braaksma | Date | Re: [xsl] xalan and replace "regex", Mansour |
| Month |