Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display semi-random xml attribute with value

Status
Not open for further replies.
Feb 7, 2007
7
US
I am trying to use XSL to transform an XML element's attribute and value, however the attribute is always different but always in the same place (it is the fifth attribute in the element). Is there a way to display this attribute and its value knowing its place (5th attribute) but not its name? Unfortunately I have no control over the XML I am working with.

Exmaple:
<CustomIndicator targetCategory="3" targetClassification="1" targetNumber="4">
<Source category="39" classification="-1" number="2" />
<Combine target="A" type="OneToOne" sourceCount="1" sourceCount1="CL-1CA39N2" CL-1CA39N2="S" />
<Combine target="U" type="OneToOne" sourceCount="1" sourceCount1="CL-1CA39N2" CL-1CA39N2="U" />
<Combine target="N" type="OneToOne" sourceCount="1" sourceCount1="CL-1CA39N2" CL-1CA39N2="N" />
</CustomIndicator>
<CustomIndicator targetCategory="3" targetClassification="1" targetNumber="5">
<Source category="79" classification="-1" number="3" />
<Combine target="Y" type="OneToOne" sourceCount="1" sourceCount1="CL-1CA79N3" CL-1CA79N3="Y" />
<Combine target="M" type="OneToOne" sourceCount="1" sourceCount1="CL-1CA79N3" CL-1CA79N3="X" />
<Combine target="H" type="OneToOne" sourceCount="1" sourceCount1="CL-1CA79N3" CL-1CA79N3="N" />
<Combine target="H" type="OneToOne" sourceCount="1" sourceCount1="CL-1CA79N3" CL-1CA79N3="E" />
</CustomIndicator>
<CustomIndicator targetCategory="11" targetClassification="1" targetNumber="2">
<Source category="39" classification="-1" number="13" />
<Combine target="D" type="OneToOne" sourceCount="1" sourceCount1="CL-1CA39N13" CL-1CA39N13="D" />
<Combine target="E" type="OneToOne" sourceCount="1" sourceCount1="CL-1CA39N13" CL-1CA39N13="E" />
<Combine target="N" type="OneToOne" sourceCount="1" sourceCount1="CL-1CA39N13" CL-1CA39N13="M" />
<Combine target="O" type="OneToOne" sourceCount="1" sourceCount1="CL-1CA39N13" CL-1CA39N13="N" />
</CustomIndicator>

The attribute is the 5th attribute of the Combine element.

Thanks in advance for any help!
 
Sure is.

You use the attribute axis, which may be abbreviated with the commercial at (@) character.

So, if I wanted the name of the fifth attribute on the third <Combine> element in the second <CustomerIndicator> element, i would use an XPath expression something like this.
Code:
local-name(/CustomIndicator[2]/Combine[3]/@*[5])

This is short for:
Code:
local-name(/CustomIndicator[position()=2]/Combine[position()=3]/attribute::*[position()=5])

Easy! :-D

Tom Morrison
 
Tom,

Thank you very much. It may have been easy for you but it has been holding me back from finishing something for 2 days now. I've figured out most everything I needd to know with XML/XSL but the XPath stuff was throwing me. Your help is greatly appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top