RE: [xsl] How to extract value of variable number of attributes in an XML tag through XSL?

Subject: RE: [xsl] How to extract value of variable number of attributes in an XML tag through XSL?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 16 Nov 2004 18:53:22 -0000
<xsl:copy-of select="@*"/> 

copies all the attributes of the context node.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Govil, Anoop (Contractor) [mailto:Anoop.Govil@xxxxxxxxxxxxxxxx] 
> Sent: 16 November 2004 14:38
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] How to extract value of variable number of 
> attributes in an XML tag through XSL?
> 
> Hello,
> 
> I have a question regarding how to extract the attributes of 
> an XML tag.
> Here is sample XML:
> 
> <PAGE>
> 	<Table_Details>
> 		<table align="center" bgcolor="#cccccc" border="1"
> height="45" width="350">
> 		<tr align="center" bgcolor="#cccccc" valign="middle">
> 		<td bgcolor="#cccccc">
> 		row 1 cell 1
> 		</td>
> 		<td align="" bgcolor="" colspan="" height="" nowrap=""
> rowspan="" valign="" width="">
> 		<b>row 1 cell 2</b>
> 		</td>
> 		</tr>
> 	</Table_Details>
> </PAGE>
> 
> Now, I need to get the attribute of the <table>, <tr> and 
> <td> tags which
> are under 	<Table_Details> parent tag. My problem is that 
> I don't know
> for sure how many attributes each of these (table, tr and td) 
> tags may have,
> they may have zero to multiple attributes. For example in 
> above example,
> under 'td' there are variable number of attributes and the 
> total number is
> not fixed. I have to output all these attributes that 
> currently exist in
> each of these tags (table, tr and td) and also add some more fixed
> attributes such as class="", etc. for each of these (table, 
> tr and td). 
> 
> If I could loop through the list of attributes in these, it 
> could be easy to
> implement so that I could get to table tag and loop through 
> its attributes
> list and add more attributes also. But I don't know how to do 
> that. Because
> I don't know for sure what attributes may be present each 
> time, I can't
> hardcode each attribute's value in final output. Please 
> suggest if there
> could be an implementation for what I am trying to do.
> 
> Thanks in advance.
> 
> Anoop

Current Thread