RE: [xsl] generate unknow table

Subject: RE: [xsl] generate unknow table
From: "John Wang" <jwang@xxxxxxxxxxx>
Date: Wed, 13 Jun 2001 09:53:05 -0500
Hi, Tom

I don't know how many thanks I can say to you, I really
appreciate your help, it solves my big problem. Only
thing I can do is post the final result in case someone
else wants to do the simillar stuff. I would like to let
you know, I have learned a lot from your example, before
studying your example, I never realized that so powerful
of using <xsl:variable>. Thanks again and again!

Here is the XML pre-generated from display control file:

<?xml version="1.0"?>
	<field id="sel" ND="flag80">Sel</field>
	<field id="sflbr">Br</field>
	<field id="sflcyc">Cycle</field>
	<field id="sfsts">P/I Status Description</field>
	<field id="pidate">P/I Date</field>

It carries table field title, name and order information.
It also tell us that wheter to display field "sel" is
determined by "flag80".

Here is the XML generated from database:

<?xml version="1.0"?>
			<sel flag80="on">12</sel>
			<sfsts>This is a description</sfsts>
			<sel flag80="off">11</sel>
			<sfsts>This is a description too</sfsts>

Here is the XSL that merge this two XML together and make
a HTML table. I really think it is very good sample code,
and can be used again and again.

<?xml version='1.0' encoding='utf-8' ?>
<xsl:stylesheet version="1.0"
<xsl:output method="html"/>

	<xsl:variable name="display" select="document(&apos;title.xml&apos;)"/>
	<!-- ////// Get list of field names ////////-->
	<xsl:variable name="fields" select="$display/title/field/@id"/>
	<xsl:variable name="titles" select="$display/title/field"/>
	<!--/////// Get name of flag ////////-->
	<xsl:variable name="display-flag"
	<!--////// Main Template ////////-->
	<xsl:template match="/display">
			<title>XSl Example for Unknown &quot;sel&quot; Flag Name</title>
			<table border="1">
				<xsl:call-template name="headers"/>
				<xsl:call-template name="data"/>
	<!--/////// Row headers //////-->
	<xsl:template name="headers">
			<xsl:for-each select="$titles">
					<xsl:value-of select="."/>
	<!--/////// Table body //////-->
	<xsl:template name="data">
		<xsl:for-each select="data/record">
				<xsl:call-template name="get-record"/>
	<!--/////// Format each row ////////-->
	<xsl:template name="get-record">
		<xsl:variable name="row" select="."/>
		<xsl:for-each select="$fields">
			<xsl:variable name="field" select="../@id"/>
			<xsl:variable name="cell" select="$row/*[name()=$field]"/>
			<xsl:variable name="flag" select="$cell/@*[$display-flag]"/>
				<xsl:if test='not($flag) or $flag=&quot;on&quot;'>
					<xsl:value-of select="$cell"/>

I have tested your code, it works great unless it shows the
field name instead of title provided in the <title> element.
I just follow your example, make little change and it works.
It looks like you assign me a homework. Here is the final result:

  <title>XSl Example for Unknown "sel" Flag Name</title>
  <table border="1">
      <th>P/I Status Description</th>
      <th>P/I Date</th>
      <td>This is a description</td>
      <td>This is a description too</td>

We can close individual field "sel" at run time by setting the

Thanks again, Tom.


 XSL-List info and archive:

Current Thread