I would like to categorize results from an XPath under headings by element name (and then by same attribute names). Note: XML data could be inconsistent and some elements with t
This stylesheet:
ElementName
Result:
ElementName
color
cute
name
type
dog
brown
yes
Frank
Lab
ElementName
color
cute
name
cat
brown
yes
Fluffy
cat
brown
no
Lucy
ElementName
color
cute
name
dog
brown
no
Spot
dog
brown
yes
Rover
ElementName
color
name
cat
brown
Princess
Note: This assumes that all elements having the same number of attributes have also the same attribute's name (like in your input sample).
EDIT: Better ouput markup.
EDIT 2: Another kind of solution: one header with all posible attribute (like CSV pattern) and order element by attribute count and name.
ElementName
Result:
ElementName
color
cute
name
type
dog
brown
yes
Frank
Lab
cat
brown
yes
Fluffy
cat
brown
no
Lucy
dog
brown
no
Spot
dog
brown
yes
Rover
cat
brown
Princess
Note: This runs through the tree twice but without extension. Exact match for desired output without extensions would require to mimic key mechanism like this: run through the tree adding new keys (name of element plus attributes' names) to a param, then again for every key run through the tree filtering node by key (could be a little optimization keeping a node set for non matching elements...). Worst case (every node with distinc key) will pass trough a node: N (for key building) + (N + 1) * N / 2