Subject: [xsl] Newbie getting desperate From: "Ouagadougou Womp" <gogge1@xxxxxxxxx> Date: Sat, 25 Feb 2006 09:14:16 -0500 |
Hello First of all I would like to apologies for this probably simple question. But since english is not my first language I have failed to find all the solutions that is probably out there. To my problem. I am trying to extract data from an XML file using this script: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <head></head> <table border="1"> <xsl:for-each select="//data"> <tr> <td><xsl:value-of select="//field[@tag='123']/subfield[@id='a']"/></td> <td><xsl:value-of select="//field[@tag='123']/subfield[@id='b']"/></td> <td><xsl:value-of select="//field[@tag='321']/subfield[@id='a']"/></td> <td><xsl:value-of select="//field[@tag='999']/subfield[@id='a']"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> I get a table with the first found instance of each select, repeated as many times as there are <data> tags. Here is an abbreviated XML example. <file> <data> <field tag="123"> <subfiled id="a">I belong to the first data</subfield> </field> <field tag="321"> <subfield id="a">No1</subfield> </field> </data> <field tag="123"> <subfiled id="a">I belong to the second data</subfield> </field> <field tag="999"> <subfiled id="a">I am a proud representative of No2</subfield> </field> </data> And here is the result as translated into HTML (put in quotes to prevent unexpected things): <!-- <html> <head></head> <body> <table> <tr> <td>I belong to the first data</td><td></td><td>No1</td><td>I am a proud representative of No2</td> </tr> <tr> <td>I belong to the first data</td><td></td><td>No1</td><td>I am a proud representative of No2</td> </tr> </body> </html> //--> as opposed to the expected result: <!-- <html> <head></head> <body> <table> <tr> <td>I belong to the first data</td><td></td><td>No1</td><td></td> </tr> <tr> <td>I belong to the second data</td><td></td><td></td><td>I am a proud representative of No2</td> </tr> </body> </html> //--> I have tried an XML set with many <data> entries. And every table row starts with the first found <field tag='123'><subfield id='a'>, continues with the first (and in my case only) found <field tag='321'><subfield id='a'> belonging to a different <data> and of course ends with the first found 999+a. This leaves me with a table filled with identical rows, allthough my XML data differs. What do I do wrong? Again foregive me for asking such a simple question, but I am getting frustrated. I have succeeded earlier with simpler scripts. But now have hit rock bottom. Cheers Anders -- _______________________________________________ Search for businesses by name, location, or phone number. -Lycos Yellow Pages http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default.asp? SRC=lycos10
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Can't figure out why this, Andrew Franz | Thread | RE: [xsl] Newbie getting desperate, Michael Kay |
Re: [xsl] Re: Does anyone know how , M. David Peterson | Date | RE: [xsl] Newbie getting desperate, Michael Kay |
Month |