abusemind
abusemind

Reputation: 213

About the xsl processing

I am using xsl to transform a xml to html. A table is created in the html but some problem of the unduplicated items appear. If I use a unique key to form the table(xsl for-each of every row), for example, context, but this attribute is not in the table.

the final table is like this

context(invisible)  attr1  attr2 attr3
1                     A      b    x
2                     A      b    x
3                     A      c    x
4                     B      a    x

Now at the same time, I want to use attr1&attr2 both as another primary key, which means that item 1 and item 2 is just the same(one will be eliminated automatically during the xsl processing), How xsl achieve this goal?

Upvotes: 0

Views: 91

Answers (1)

Robert Christie
Robert Christie

Reputation: 20685

You can filter matches on the 2 attributes by using the preceding-sibling axis. Assuming this xml:

<?xml version="1.0" encoding="UTF-8"?>
<doc>
   <row attr1="A" attr2="b" attr3="x"/>
   <row attr1="A" attr2="b" attr3="x"/>
   <row attr1="A" attr2="c" attr3="x"/>
   <row attr1="B" attr2="a" attr3="x"/>
</doc>

This XPath will return only those rows where attributes attr1 and attr2 are not duplicates.

//row[preceding-sibling::row[@attr1 = self::*/@attr1 and @attr2=self::*/@attr2]]

Upvotes: 2

Related Questions