Subject: [xsl] How to Process when Row data could be either elements or attributes From: Imrran Wahid <devguy2003@xxxxxxxxx> Date: Thu, 20 Mar 2003 13:09:53 -0800 (PST) |
I have come upon another stumper and once again I hope one of the more experienced minds can help as you have done in the past. I am creating tables from an xml that could have the column data in the rows represented either as elements or as attributes. I have solved the problem when the data is in elements. Now I want so that it handles the data when it is in attributes. I do not want to use separate stylesheets. So I tried to incorporate the solution to the second part into the working solution to the first part. eg. of xml to transform - row data in elements: <fruits> <oranges> <orange> <type>navel</type> <origin>Uruguay</origin> </orange> <orange> <type>temple</type> <origin>Brazil</origin> </orange> </oranges> <apples>... <apples> </fruits> eg of xml to transform - row data in attributes: <fruits> <oranges> <orange type="navel" origin="Uruguay"/> <orange type="temple" origin="Brazil"/> </oranges> <apples>... <apples> </fruits> The templates I used to transform when the row data is in elements are: <xsl:template match="//Fruits/*[count(./*) > 0]" mode="regularTable"> <table> <tr> <!-- this is the row with the col headings --> <xsl:for-each select="./*[1]/*"> <th><xsl:value-of select="name(.)"/></th> </xsl:for-each> </tr> <xsl:apply-templates select="*"/></table> </xsl:template> <xsl:template match="//Fruits/*[count(./*) > 0]/*"> <tr> <xsl:apply-templates select="*"/> </tr> </xsl:template> <xsl:template match="*"> <td> <xsl:value-of select="normalize-space(text())"/> </td> </xsl:template> How do I modify these to transform when the row data is in attributes? I was only able to get the column headings to transform properly by making a change(select="./*[1]/*|./*[1]/@*") in the template as shown below: <xsl:template match="//Fruits/*[count(./*) > 0]" mode="regularTable"> <table> <tr> <!-- this is the row with the col headings --> <xsl:for-each select="./*[1]/*|./*[1]/@*"> <th><xsl:value-of select="name(.)"/></th> </xsl:for-each> </tr> <xsl:apply-templates select="*"/></table> </xsl:template> I could not get the cell data to populate...whatever i try doesn't seem to work for me. Appreciate any help. Thanks __________________________________________________ Do you Yahoo!? Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop! http://platinum.yahoo.com XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] REPOST: Solution: Efficient g, Robbert van Dalen | Thread | Re: [xsl] How to Process when Row d, Imrran Wahid |
[xsl] REPOST: Solution: Efficient g, Robbert van Dalen | Date | [xsl] Looping through attributes.., Karl Stubsjoen |
Month |