By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,501 Members | 2,805 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,501 IT Pros & Developers. It's quick & easy.

XML data to HTML table - please help!

P: n/a
Hi all!

I am currently involved in a project in which I am supposed to write a
XSLT-transformation sheet for some XML data.

I will outline the situation first:
I've got one large XML file which is roughly build up like this:

<forms>
<subform>
<questions>
<question>
<text>ABC count</text>
<number=1010>
<answer>
<value>1</value>
</answer>
</question>
<question>
<text>ABC score</text>
<number=1020>
<answer>
<value>10</value>
</answer>
</question>
<question>
<text>DEF score</text>
<number=1030>
<answer>
<value>3</value>
</answer>
</question>
<question>
<text>DEF count</text>
<number=1040>
<answer>
<value>2</value>
</answer>
</question>
</questions>
</subform>
</forms>
....etc...

I want this data to be in a table like this:
TYPE SCORE COUNT
ABC 10 1
DEF ...etc.

The problem being that not all of the question/answer tags are needed.
So I need to loop through all question-nodes (roughly 100)and extract
only a few elements for the table. The needed tags are recognisable
because there "number" is above 1000. Furthermore, there are only 3
seperate values per type (I've used only 2 for my example).

I've started as follows:
First I loop through all the question-nodes via a <xsl:for-each> loop.
I then test each question-node for a "number"-tag that exceeds 1000 (I
only need these nodes for my table).

These two steps bring me at the point where I can fill my table. It's
at this point that I am stuck. I can't figure out how I am supposed to
know when to start a new row. To my knowledge, it's not possible to
keep track of a counter in XSLT (if this were possible, I could just
count the number of columns I'd have filled). I've tried using
<xsl:when> statements to start a new row using hardcoded borders (for
example: I know the row ends after a ABC->COUNT node), but this is not
possible because of the nested structure of XML.

I don't know what to do now, so please help..

Thanks in advance,

Alke Wiebenga
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


A. Wiebenga wrote:
I've got one large XML file which is roughly build up like this:

<forms>
<subform>
<questions>
<question>
<text>ABC count</text>
<number=1010>

^^^^^^
That doesn't look to be well-formed to me.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2

P: n/a

I've started as follows:
First I loop through all the question-nodes via a <xsl:for-each> loop.
I then test each question-node for a "number"-tag that exceeds 1000 (I
only need these nodes for my table).


No need to select everything and then throw most away, just select the
things you need, something like this if I understood your structure
correctly.
<table>
<tr>
<td>type</td>
<td>score</td>
<td>count</td>
</tr>
<xsl:for-each select="question[number &gt; 1000][contains(text,'count')]">
<tr>
<td><xsl:value-of select="substring-before(text,' count')"/></td>
<td><xsl:value-of select="preceding-sibling::question[1]/answer/value"/></td>
<td><xsl:value-of select="answer/value"/></td>
</tr>
</xsl:for-each>
</table>

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.