This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Retrieving named elements from separate tree


I'm looking for advice as to how to make the following work. It 
seems to me that it "should" be possible, but I'm not having 
much luck.

I'm trying to use html table column metadata (eventually this 
will end up in a separate xml file) to define the alignment of 
each column. 

The xml file follows.

myData.xml ---------------------------------
<?xml version="1.0" ?>

<TradeData date='2002-03-18'>
	<ColumnInfo>
		<column colname="TradeType" align="left"/>
		<column colname="TradeId" align="center"/>
		<column colname="TradeValue" align="right"/>
	</ColumnInfo>

	<Trades>
		<TradeEntry>
			<TradeType>TypeA</TradeType>
			<TradeId>12345</TradeId>
			<TradeValue>100.00</TradeValue>
		</TradeEntry>
		<TradeEntry>
			<TradeType>TypeB</TradeType>
			<TradeId>45678</TradeId>
			<TradeValue>500.00</TradeValue>
		</TradeEntry>
		<TradeEntry>
			<TradeType>TypeC</TradeType>
			<TradeId>56789</TradeId>
			<TradeValue>350.00</TradeValue>
		</TradeEntry>
	</Trades>
</TradeData>
----------------------------------------------------------
The xsl file follows.
myData2html.xsl --------------------------------
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:template match="/TradeData">	
	<html><body>
	<p>Prepared on <xsl:value-of select="@date"/></p>
	<xsl:apply-templates select="//Trades" />	
	</body></html>
 </xsl:template>

<xsl:template match="Trades">	
	<p>Transactions:</p>
	<table border="1">
		<tr>
			<xsl:for-each select="TradeEntry[position()=1]/*">
				<th><xsl:value-of select="name()"/></th>
			</xsl:for-each>
		</tr>
		<xsl:apply-templates select="TradeEntry"/>
	</table>
</xsl:template>
	
<xsl:template match="TradeEntry">
	<tr><xsl:apply-templates/></tr>
</xsl:template>

<xsl:template match="TradeEntry/*">
 <td>	
  <xsl:attribute name="align"><xsl:value-of
select="//ColumnInfo/column[@colname='TradeId']/@align"/></xsl:attribute>
  <xsl:value-of select="."/>
 </td>
</xsl:template>

</xsl:stylesheet>
--------------------------------------------------------------------

I've declared an attribute for the <td> tag, which I'm trying to set to the 
current column's align attribute. If I hard-code the colname ('TradeId') 
then it works. What I would like to do is to replace [@colname='TradeId']
with something like [@colname=name()]. This (and several variations I've 
tried) does not work. 

Thanks,
- Steve

- Stephen Friedland
- stephen_r_friedland@fleet.com


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]