Skip to content Skip to sidebar Skip to footer

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...

<tabtableWidth="500">
    ....

There are two ways to make use of the attribute in the XSLT. Firstly, the more verbose way....

<xsl:templatematch="Tab"><tablecellpadding="6"cellspacing="0"align="center"><xsl:attributename="width"><xsl:value-ofselect="@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"