xsl-list
[Top] [All Lists]

Newbie getting desperate

2006-02-25 07:14:16
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[(_at_)tag='123']/subfield[(_at_)id='a']"/></td>
<td><xsl:value-of 
select="//field[(_at_)tag='123']/subfield[(_at_)id='b']"/></td>
<td><xsl:value-of 
select="//field[(_at_)tag='321']/subfield[(_at_)id='a']"/></td>
<td><xsl:value-of 
select="//field[(_at_)tag='999']/subfield[(_at_)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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>