[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: table type output in text fromat -ONE DOUBT
Here's one way of doing it, based on your sample source file. Modify it to account for more or less variation in your source data, and to make the tables as pretty as you want. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:strip-space elements="*"/> <xsl:template match="configuration"> <!-- make the acp_info table --> <xsl:apply-templates select="acp_info[1]" mode="header"/> <xsl:apply-templates select="acp_info"/> <xsl:text> </xsl:text> <!-- make the channel_info table --> <xsl:apply-templates select="channel_info[1]" mode="header"/> <xsl:apply-templates select="channel_info"/> <xsl:text> </xsl:text> <!-- make the subsystem_id table --> <xsl:text>subsystem_id: </xsl:text> <xsl:text> cu01 cu02 cu03 cu04 etc.</xsl:text> <xsl:text> 00-3f </xsl:text> <xsl:apply-templates select="subsystem_id[position() mod 4 = 1]"/> <xsl:text> 40-7f </xsl:text> <xsl:apply-templates select="subsystem_id[position() mod 4 = 2]"/> <xsl:text> 80-bf </xsl:text> <xsl:apply-templates select="subsystem_id[position() mod 4 = 3]"/> <xsl:text> c0-ff </xsl:text> <xsl:apply-templates select="subsystem_id[position() mod 4 = 0]"/> </xsl:template> <xsl:template match="acp_info|channel_info" mode="header"> <!-- write a header line consisting of the names of all the child elements --> <xsl:value-of select="concat(name(),': ')"/> <xsl:for-each select="*"> <xsl:variable name="padded-str"> <xsl:call-template name="pad-string"> <xsl:with-param name="str" select="name(.)"/> <xsl:with-param name="len"> <xsl:choose> <xsl:when test="name() = 'pb'"> <xsl:value-of select="5"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="10"/> </xsl:otherwise> </xsl:choose> </xsl:with-param> <xsl:with-param name="quad" select="'center'"/> </xsl:call-template> </xsl:variable> <xsl:value-of select="$padded-str"/> </xsl:for-each> </xsl:template> <xsl:template match="name|pb|pk|serial|factory"> <xsl:variable name="padded-str"> <xsl:call-template name="pad-string"> <xsl:with-param name="str" select="."/> <xsl:with-param name="len"> <xsl:choose> <xsl:when test="name() = 'pb'"> <xsl:value-of select="5"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="10"/> </xsl:otherwise> </xsl:choose> </xsl:with-param> <xsl:with-param name="quad"> <xsl:choose> <xsl:when test="name() = 'pb' or name() = 'pk'"> <xsl:text>center</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>left</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:with-param> </xsl:call-template> </xsl:variable> <xsl:if test="name() = 'name'"> <xsl:text> </xsl:text> </xsl:if> <xsl:value-of select="$padded-str"/> </xsl:template> <xsl:template match="subsystem_id"> <!-- if all inputs are same length, just append spaces, otherwise you will have to invoke pad-string --> <xsl:value-of select="concat(.,' ')"/> </xsl:template> <xsl:template name="pad-string"> <xsl:param name="str"/> <xsl:param name="len"/> <xsl:param name="quad" select="'left'"/><!-- or 'right' or 'center' --> <xsl:choose> <xsl:when test="string-length($str) >= $len"> <xsl:value-of select="substring($str,1,$len)"/> </xsl:when> <xsl:otherwise> <xsl:choose> <xsl:when test="$quad = 'right'"> <xsl:call-template name="pad-string"> <xsl:with-param name="str" select="concat(' ',$str)"/> <xsl:with-param name="len" select="$len"/> <xsl:with-param name="quad" select="$quad"/> </xsl:call-template> </xsl:when> <xsl:when test="$quad = 'center'"> <xsl:call-template name="pad-string"> <xsl:with-param name="str" select="concat(' ',$str,' ')"/> <xsl:with-param name="len" select="$len"/> <xsl:with-param name="quad" select="$quad"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:call-template name="pad-string"> <xsl:with-param name="str" select="concat($str,' ')"/> <xsl:with-param name="len" select="$len"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> I have only tested with xt, so I don't know what the problem with xalan would be. Just use the standard xsl namespace. Later, Paul Tyson, Principal Consultant Precision Documents paul@xxxxxxxxxxxxxxxxxxxxxx http://precisiondocuments.com "The art and science of document engineering." ----- Original Message ----- From: "Praveen G" <praveeng@xxxxxxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Wednesday, October 03, 2001 3:30 AM Subject: Re: table type output in text fromat -ONE DOUBT > Hi paul and wendell , > Thanks for responding. I am using xalan-j_2_2_d10 parser for my xml work. > In this we have a java program > (DOM2DOM .java) which is used for displaying xml text output on the command > prompt. Apart from this , we are using Microsoft Internet explorer version > 6.0 for viewing xml documents. > Basically, i am not able to figure out how to utilize the code paul has sent > yesterday(I am getting domparser exceptions in xalan.) > I am pasting a sample xml document of ours here. i will specify the required > text table output format also. . i have to design some 20 odd tables like > that in text format. If u can please give a sample code for this xml > document here, i can use the same way of designing for the rest of my > tables. i will also paste paul's code at the end so that he need not refer > back. > MY XML DOCUMENT :: > <?xml version="1.0"?> > <?xml-stylesheet type="text/xsl" href="config.xsl"?> > <configuration_package> > <configuration> > <acp_info> > <name>WP424-c</name> > <pb>5</pb> > <pk>A/U10</pk> > <serial>HCJ02454</serial> > <factory>HiCAM</factory> > </acp_info> > <acp_info> > <name>WP426-b</name> > <pb>6</pb> > <pk>A/U10</pk> > <serial>HCJ02479</serial> > <factory>HiCAM</factory> > </acp_info> > <channel_info> > <name>SH2132-A</name> > <pb>2</pb> > <pk>E5</pk> > <serial>SH2120B9</serial> > <factory>STR</factory> > </channel_info> > <subsytem_id>001</subsytem_id> > <subsytem_id>002</subsytem_id> > <subsytem_id>003</subsytem_id> > <subsytem_id>004</subsytem_id> > <subsytem_id>005</subsytem_id> > <subsytem_id>006</subsytem_id> > </configuration> > </configuration_package> > My REQUIRED TEXT FORMAT IS LIKE THIS: > Acp_info: > name pb pk serial factory > WP424-c 5 A/U10 HCJ02454 Hicam > WP426-b 6 A/U10 HCJ02479 Hicam > > channel_info : > name pb pk serial factory > SH2132-A 2 E5 SH2120B9 STR > > Subsystem_id : > > cu01 cu02 cu03 -->these are table columns. > 00-3f 0001 0005 > 40-7f 0002 0006 > 80-bf 0003 > co-ff 0004 > > 1)all the table names will appear only once. > 2) i have asked a question about the subsystem _id table format and paul has > provided a solution for that before(in html). Thanks a lot for that. now , i > need a similar table format in text. > 3) can you please explain to me, what all i have to do to view this in > notepad(i have microsoft I.E -6.0 and xalan parser with me.) If u can give > me a sample stylesheet for this code above, i'll try it out in xalan. please > specify the namespace to be used also. > 4)Basically, this kind of design will suffice, any improvement in the table > look above this will be a bonus for me. > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|