Re: [xsl] one stylesheet template for mutiple tables

Subject: Re: [xsl] one stylesheet template for mutiple tables
From: Mulberry Technologies List Owner <xsl-list-owner@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 31 Jul 2003 12:39:16 -0400
>Date: Thu, 31 Jul 2003 11:25:06 -0400
>To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
>Subject: Re: [xsl] one stylesheet template for mutiple tables
>In-Reply-To: <60098A15DB40D511B69F00508B8B84BF02AB13E0@HOTH>
>Mime-Version: 1.0
>Content-Type: text/plain; charset="us-ascii"; format=flowed
>
>Jerome:
>
>This can be done.
>
>I can think of two possible approaches to this.
>
>1. Write a "meta-stylesheet" that will generate a stylesheet from your
>config file, which in turn gets applied to your data. The XSL FAQ has
>details on writing stylesheets to generate stylesheets.
>
>2. Use templates that match all nodes, then apply conditional tests to sort
>things out, as in
>
><xsl:variable name="columns" select="document('config.xml')//col"/>
>
><xsl:template match="QueryReturn/*">
>   <!-- this variable assignment can be further constrained to check which
>        table you are in: not done in this simple example -->
>   <xsl:variable name="thiscolumn"
>select="$columns[@node=local-name(current())]"/>
>
>   ... do whatever else: your header is now "$thiscolumn/@header ... and
>   $thiscolumn will be an empty node set if there was no match to your node
>name ...
>
></xsl:template>
>
>What's happening here is that the $columns variable is being set up as a
>kind of "lookup table" (search for lookup tables in XSLT in the FAQ or
>using a search engine to find out more about this technique).
>
>Whether 1. or 2. is better for you, depends....
>
>With any luck this should be enough to get you started. Post again if you
>get stuck, with more detail (such as desired output). (Unfortunately
>chances are low that I'll be able to answer for the next week or so, but
>someone else probably can.)
>
>Cheers,
>Wendell
>
>At 03:42 PM 7/30/2003, you wrote:
>>Greetings,
>>
>>I am wondering if anyone thinks this can be done..  I would like to create
>>one stylesheet that can be used against multiple tables, using information
>>from another xml file..
>>
>>let me try to explain..
>>
>>I have an existing application which has an config xml file which contains
>>information regarding a number of individual tables.
>>This Config XML is used in another part of the application and i would like
>>to use it to generate the xsl so i don't have to worry about changing the
>>stylesheets if the user edits
>>this application config.
>>
>>This Config xml file tells me the column name and the column header, and the
>>order to which the xml files are to appear. If columns are not in the
>>config.xml then i don't wanna display them even though they may exist in the
>>table source xml. Note each table can have a different number of columns and
>>this can change.. see Config XML.
>>
>>Config XML..
>>
>><config>
>>         <table id = "table1">
>>                 <col header = "Name" node = "Na"></col>
>>                 <col header = "Description" node = "Desc"></col>
>>         </table>
>>
>>         <table id "table2">
>>                 <col header = "Town" node = "Twn"></col>
>>                 <col header = "Province" node = "Pr"></col>
>>                 <col header = "Street" node = "St"></col>
>>         </table>
>></config>
>>
>>
>>the data XML for table 1
>>
>><NewDataSet>
>>         <QueryReturn>
>>                 <Na>Mary</Na>
>>                 <NotShown>AAA</NotShown>
>>                 <Desc>a nice girl</Desc>
>>         </QueryReturn>
>>
>>         <QueryReturn>
>>                 <Na>Jane</Na>
>>                 <NotShown>BBB</NotShown>
>>                 <Desc>a naughty girl</Desc>
>>         </QueryReturn>
>></NewDataSet>
>>
>>the data XML for table 2
>>
>><NewDataSet>
>>         <QueryReturn>
>>                 <NotShown>XXX</NotShown>
>>                 <Twn>Moncton</Twn>
>>                 <St>Crowell Dr</St>
>>         </QueryReturn>
>>
>>         <QueryReturn>
>>                 <NotShown>YYY</NotShown>
>>                 <Twn>Halifax</Twn>
>>                 <St>High St</St>
>>         </QueryReturn>
> ></NewDataSet>
>
>
>======================================================================
>Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
>Mulberry Technologies, Inc.                http://www.mulberrytech.com
>17 West Jefferson Street                    Direct Phone: 301/315-9635
>Suite 207                                          Phone: 301/315-9631
>Rockville, MD  20850                                 Fax: 301/315-8285
>----------------------------------------------------------------------
>   Mulberry Technologies: A Consultancy Specializing in SGML and XML
>======================================================================



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread