[oXygen-user] Newbie question on XSLT - how to generate table columns dynamically

Sorin Ristache
Mon Jun 19 08:58:30 CDT 2006


Hello Jamie,

You can find in the attachment an XSLT stylesheet which generates an 
HTML table with the requested columns. It can be applied to XML files 
with the same structure (result/row/*) and with any number of child 
elements inside the "row" element. The names of the child elements are 
the names of the HTML table columns (see the <xsl:for-each 
select="row[1]/*"> instruction). Also each "row" element of the XML 
source fills a row in the HTML table (see <xsl:template match="row"> and 
<xsl:template match="row/*">). To apply the XSLT stylesheet just open it 
in <oXygen/> and press the "Apply Transformation Scenario" toolbar 
button, which will ask you to define a transformation scenario. Press 
the "New" button to open the Edit scenario dialog, in the "XML URL" 
field of the XSLT tab select your XML file and check the "Show As XHTML" 
checkbox on the Output tab. Press OK to end the definition of the new 
scenario and press the "Transform now" button to run the transformation 
and see the HTML table result in a special XHTML view at the bottom of 
the <oXygen/> window.


I hope that helps,
Sorin


Jamie Wang wrote:
> Hi, I am new to XSLT and have a question on how to dynamically generate 
> columns in XSL style sheet that can be applied generic xml files that 
> has the same document structure but with different number of columns and 
> column names. The XML file is shown below. In this case, the number of 
> columns is 3 and column names are the elements’ name (e.g., COUNTRY_ID, 
> COUNTRY_NAME and REGION_ID.  Thanks in advance for your assistance. -Jamie
> 
>  
> 
>  
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> 
> <?xml-stylesheet type="text/xsl" href="http://rome:18080/countries.xsl"?>
> 
>  
> 
> <result>
> 
> <row>
> 
>     <COUNTRY_ID>AR</COUNTRY_ID>
> 
> <COUNTRY_NAME>Argentina</COUNTRY_NAME>
> 
>       <REGION_ID>2.0</REGION_ID>
> 
> </row>
> 
> <row>
> 
>     <COUNTRY_ID>AU</COUNTRY_ID>
> 
>       <COUNTRY_NAME>Australia</COUNTRY_NAME>
> 
>       <REGION_ID>3.0</REGION_ID>
> 
> </row>
> 
> result>
> 
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> oXygen-user mailing list
> 
> http://www.oxygenxml.com/mailman/listinfo/oxygen-user
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jamie.xsl
Type: text/xml
Size: 1106 bytes
Desc: not available
Url : http://www.oxygenxml.com/pipermail/oxygen-user/attachments/20060619/c3e58b71/attachment.xsl 


More information about the oXygen-user mailing list