Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML node value in html tag via xslt

Status
Not open for further replies.

goofy78270

Technical User
Jul 24, 2007
38
US
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
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>
 
><td colspan="{$Column}" align="center">
[tt]<td colspan="{[red]Column[/red]}" align="center">[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top