goofy78270
Technical User
Is it possible to input a node value into a html tag within an xslt?
I have the following code where I tried to input the column variable into the <td colspan> tag in the middle of the code, but nothing displays. As soon as I remove the tag or hard code the value, everything works fine.
XSL file
Sample XML file
I have the following code where I tried to input the column variable into the <td colspan> tag in the middle of the code, but nothing displays. As soon as I remove the tag or hard code the value, everything works fine.
XSL file
Code:
<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
<!-- Define template for xsl -->
<xsl:template match="/">
<!-- Define variable for empty string -->
<xsl:variable name="empty_string"/>
<!-- Define main table headings and layout -->
<html>
<body>
<table>
<tr class="Heading1">
<xsl:for-each select="MasterKey/Attribute">
<xsl:choose>
<xsl:when test="Column = 1">
<td rowspan="2">
<xsl:value-of select="Name" />
</td>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="Position = 1">
<td colspan="{$Column}" align="center">
<xsl:value-of select="Name" />
</td>
</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</tr>
<tr class="Heading2">
<xsl:for-each select="MasterKey/Attribute">
<xsl:choose>
<xsl:when test="Option != $empty_string">
<td rowspan="2">
<xsl:value-of select="Option" />
</td>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Sample XML file
Code:
<Attribute>
<Name>Product</Name>
<Option></Option>
<Column>1</Column>
<Position>1</Position>
</Attribute>
<Attribute>
<Name>Color</Name>
<Option>Yellow</Option>
<Column>2</Column>
<Position>1</Position>
</Attribute>
<Attribute>
<Name>Color</Name>
<Option>Red</Option>
<Column>2</Column>
<Position>2</Position>
</Attribute>
<Attribute>
<Name>Price</Name>
<Option>1.00</Option>
<Column>2</Column>
<Position>1</Position>
</Attribute>