Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

foreach table

4 views
Skip to first unread message

TomislaW

unread,
Oct 28, 2011, 7:32:34 AM10/28/11
to
Hello!

Can you help me with creating XSLT.
I have xml like this:

<root>
<table1>
<column1>a</column1>
<column2>b</column2>
</table1>
<table1>
<column1>c</column1>
<column2>d</column2>
</table1>
<table1>
<column1>e</column1>
<column2>f</column2>
</table1>
<table2>
<column1>g</column1>
<column2>h</column2>
</table2>
<table2>
<column1>i</column1>
<column2>j</column2>
</table2>
</root>

Sometimes i don't have table2, sometimes i have tabl3, table4... (I do
not know in advance the names of the tables, nor how many will be.)
I need to use same template for all tables.
My output has to be like this:

<root>
<table1>
<row>
<column1>a</column1>
<column2>b</column2>
</row>
<row>
<column1>c</column1>
<column2>d</column2>
</row>
<row>
<column1>e</column1>
<column2>f</column2>
</row>
</table1>
<table1>
<row>
<column1>g</column1>
<column2>h</column2>
</row>
<row>
<column1>i</column1>
<column2>j</column2>
</row>
</table1>
</root>

Marc

unread,
Oct 28, 2011, 4:59:02 PM10/28/11
to
perhaps something like match="*[column1]"
Marc

Le 28/10/2011 13:32, TomislaW a ᅵcrit :

TomislaW

unread,
Oct 31, 2011, 5:50:10 AM10/31/11
to

Thanks for the reply, but I made the mistake of my output should look
like this:
<root>
<table1>
<row>
<column1>a</column1>
<column2>b</column2>
</row>
<row>
<column1>c</column1>
<column2>d</column2>
</row>
<row>
<column1>e</column1>
<column2>f</column2>
</row>
</table1>
<table2>
<row>
<column1>g</column1>
<column2>h</column2>
</row>
<row>
<column1>i</column1>
<column2>j</column2>
</row>
</table2>
</root>

TomislaW

unread,
Oct 31, 2011, 7:58:23 AM10/31/11
to
How can I get unique names of tables for the xml above?
table1
table2

Marc

unread,
Oct 31, 2011, 9:47:28 AM10/31/11
to
I don't understand the problem.
Perhaps using for-each-group ?
Marc

TomislaW

unread,
Oct 31, 2011, 3:39:54 PM10/31/11
to
I don't know the names of the tables and how much different tables
will I have

<root>
<table1> ...</table1>
<anothertable> ...</anothertable>
</root>

I have xml (XmlDataDocument) from DataSet with many tables.

Marc

unread,
Nov 1, 2011, 4:18:33 AM11/1/11
to
in this case there is always the solution to create a variable with an
other XML tree
<table name="table1">

and after that you have an element and an attribute name.

I never try to do a for-each-group with name() as grouping key, or a
"key" like <key name="tables" match="/root/*/name()" use="name()"/> to
have a set of table

Marc

Le 31/10/2011 20:39, TomislaW a ᅵcrit :
0 new messages