[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Variable number of attributes
At 04:41 AM 09/30/2000 -0500, Aaron Bawcom wrote:
I'm trying to produce a single style sheet (foo.xsl) that offers the following functionality. I'm using IE 5.5. Any help would be greatly appreciated. A couple of observations: (1) The below works as long as the <ele> elements each has the same number of attributes, with the same names. If one <ele> has 4 attributes and one has 3, for example, then it will break. (2) I tested this with both of your examples under IE5.5 (July preview) release Also with Saxon; output from Saxon was: <html xmlns="http://www.w3.org/TR/REC-html40"> <head><title>Attributes to Elements</title></head> <body> <table> <tr> <td>A1</td> <td>A2</td> <td>A3</td> </tr> <tr> <td>B1</td> <td>B2</td> <td>B3</td> </tr> </table> </body> </html> (3) General idea is to: (a) Build the root of the result tree to correspond to your root <doc> element; this result tree includes a <table> element. (b) Then there's a template rule which handles the <ele> elements. Within this template rule, if this is the first <ele>, put the table headers into the rsult tree, values coming from the attribute names for this first <ele>. Then all the attributes are processed, values being placed into <td> elements. <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/REC-html40" > <xsl:template match="/doc"> <html> <head><title>Attributes to Elements</title></head> <body> <table> <xsl:apply-templates /> </table> </body> </html> </xsl:template> <xsl:template match="ele"> <xsl:if test="position()=1"> <tr> <xsl:for-each select="@*"> <th><xsl:value-of select="name()"/></th> </xsl:for-each> </tr> </xsl:if> <tr> <xsl:for-each select="@*"> <td><xsl:value-of select="."/></td> </xsl:for-each> </tr> </xsl:template> </xsl:stylesheet> ========================================================== John E. Simpson | "Curiosity killed the cat, http://www.flixml.org | but for a while I was a XML Q&A: http://www.xml.com | suspect." (Steven Wright) 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
|