I have to write an XSLT document which can be used with any XML document and display the results in an HTML table. The columns of the table all depend on how many tags there are in the XML document. I was trying to use
<xsl:value-of select="count(/*/*/)"/>
to count the number of tags.
But I want that if for instance i have:
<film>
<title></title>
<year></year>
<actor></actor>
</film>
<film>
<title></title>
<year></year>
<actor></actor>
</film>
the result would be 3 not 6 as it currently being displayed. Any solutions to this problem please?
I. Supposing:
. . . .
and:
.2. The
filmelements all have the same number of same-named columns, then you simply need:This produces the number of children elements of the first child -element of the top element of the XML document:
II. Another possibility: different
filmelements have different number of children and one of them has all children that determine the total number of columns for the table.Then, using XPath 2.0, use:
This produces the maximum number of children that a child of the top element of the XML document has:
III. Finally, if it is possible that none of the
filmelements contain all the elements for the columns, then use (what ABach already proposed):