[XSL] how could I know node attributes???

J

jaloplo

Hi,

I'm having a big problem cause I need to write attributes values
without knowing the name of these attributes. For example, my xml file
is like this:

<element id="1" name="pepe" field1="1"/>
<element id="2" name="pepe"/>
<element id="3" name="pepe" field1="a" field4="2"/>
<element id="4" name="pepe" field3="s" field4="r"/>

And I have to group these elements by 'name' attribute, and then write
all the field1 values, all the field2 values, all the field3 values,
etc., and I don't know how many fieldx values are.

The result file must be something like that:

Name | Observation
pepe | field1 1
pepe | field1 a
pepe | field3 s
pepe | field4 2
pepe | field4 r

How can I group nodes by attributes??? Or how can I know the attributes
of one node???

Thanks!!!!
 
M

Martin Honnen

<element id="1" name="pepe" field1="1"/>
<element id="2" name="pepe"/>
<element id="3" name="pepe" field1="a" field4="2"/>
<element id="4" name="pepe" field3="s" field4="r"/>

And I have to group these elements by 'name' attribute, and then write
all the field1 values, all the field2 values, all the field3 values,
etc., and I don't know how many fieldx values are.

The XPath
@*
selects all attribute nodes, the XPath
@*[starts-with(local-name(), 'field')]
selects all attribute nodes where the local name starts with the string
'field' (e.g. 'field1', 'field2', 'fieldsomething').

See
<http://www.jenitennison.com/xslt/grouping/index.xml>
for grouping.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top