Passing XML Attribute Value To HTML Atrribute Value Using XSLT
I have an XML file with certain data which I have to convert it into HTML Table. There are 3-4 table with only 2 columns and 4-5 tables with more columns. I want to pass XML attrib
Solution 1:
Assuming you have amended your XML to include an tableWidth attribute, like so...
<tab tableWidth="500">
....
There are two ways to make use of the attribute in the XSLT. Firstly, the more verbose way....
<xsl:template match="Tab">
<table cellpadding="6" cellspacing="0" align="center">
<xsl:attribute name="width"><xsl:value-of select="@tableWidth" /></xsl:attribute>
But it is often much cleaner to use Attribute Value Templates. Then you only have to do this:
<xsl:template match="Tab">
<table width="{@tableWidth}" cellpadding="6" cellspacing="0" align="center">
Both of these should output the following:
<table width="500" cellpadding="6" cellspacing="0" align="center">
Post a Comment for "Passing XML Attribute Value To HTML Atrribute Value Using XSLT"