XSL: for-each nested..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ShadowLocke
    New Member
    • Jan 2008
    • 116

    XSL: for-each nested..

    Ok, Im having some troubles fully grasping XSL. Its hard to explain with out showing so first..this is what i have so far.

    Code:
    <xsl:stylesheet version='1.0' 
    xmlns='urn:schemas-microsoft-com:office:spreadsheet'
    xmlns:xsl='http://www.w3.org/1999/XSL/Transform' 
    xmlns:msxsl='urn:schemas-microsoft-com:xslt'
    xmlns:user='urn:my-scripts'
    xmlns:o='urn:schemas-microsoft-com:office:office'
    xmlns:x='urn:schemas-microsoft-com:office:excel'
    xmlns:ss='urn:schemas-microsoft-com:office:spreadsheet' > 
    
    <xsl:template match='/'>
    <Workbook xmlns='urn:schemas-microsoft-com:office:spreadsheet'
    xmlns:o='urn:schemas-microsoft-com:office:office'
    xmlns:x='urn:schemas-microsoft-com:office:excel'
    xmlns:ss='urn:schemas-microsoft-com:office:spreadsheet'
    xmlns:html='http://www.w3.org/TR/REC-html40'>
      <xsl:apply-templates/>
    </Workbook>
    </xsl:template>
    
    <xsl:variable name='header'>
    <columnName>Column 1</columnName>
    <columnName>Column 2</columnName>
    <columnName>Column 3</columnName>
    </xsl:variable>	
    
    <xsl:template match='/*'>
    <Worksheet>
    
    <xsl:attribute name='ss:Name'>
    <xsl:value-of select='local-name(/*/*)'/>
    </xsl:attribute>
    <Table x:FullColumns='1' x:FullRows='1'>
    
    <!--header-->
    <xsl:for-each select='msxsl:node-set($header)/*'>
    	<Column ss:Width='120'/>
    </xsl:for-each>
    
    <Row>
    <xsl:for-each select='msxsl:node-set($header)/*'>
    	<Cell ss:StyleID='s21'>
    		<Data ss:Type='String'>
    			<xsl:value-of select='.'/>
    		</Data>
    	</Cell>
    </xsl:for-each>
    </Row>
    <!--/header-->
    
    <xsl:apply-templates/>
    
    </Table>
    </Worksheet>
    </xsl:template>
    
    <!--each row-->
    <xsl:template match='/*/*'>
    <Row>
    
    	<xsl:variable name = 'cNodeName'>
    		<xsl:value-of select='local-name()'/>
    	</xsl:variable>
    	
    	<xsl:variable name = 'cNodeData'>
    		<xsl:value-of select='.'/>
    	</xsl:variable>
    	
    	<xsl:for-each select='msxsl:node-set($header)/*'>
    		<xsl:if test='$cNodeName=.'>
    			<Cell>
    				<Data ss:Type='String'>
    					<xsl:value-of select='$cNodeData'/>
    				</Data>
    			</Cell>
    		</xsl:if>
    	</xsl:for-each>
    </Row>
    </xsl:template>
    <!--/each row-->
    
    </xsl:stylesheet>
    the if statement in there (line 69) is incorrect. How can I get the desired test statement to put the correct data in?
    Last edited by ShadowLocke; May 26 '08, 09:20 PM. Reason: Added line id.
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Please post your input xml data.

    Comment

    • ShadowLocke
      New Member
      • Jan 2008
      • 116

      #3
      Originally posted by jkmyoung
      Please post your input xml data.
      Code:
      <NewDataSet>
          <DataTable>
              <FULL_NAME>Actual Data Removed</FULL_NAME>
              <SPECIALTY>Actual Data Removed</SPECIALTY>
              <LOCATION>Actual Data Removed</LOCATION>
              <ENTRY_DATE>Actual Data Removed</ENTRY_DATE>
              <ACTION>Actual Data Removed</ACTION>
          </DataTable>
       
          <DataTable>
              <FULL_NAME>Actual Data Removed</FULL_NAME>
              <LOCATION>Actual Data Removed</LOCATION>
              <ENTRY_DATE>Actual Data Removed</ENTRY_DATE>
              <ACTION>Actual Data Removed</ACTION>
          </DataTable>
       
          <DataTable>
              <FULL_NAME>Actual Data Removed</FULL_NAME>
              <SPECIALTY>Actual Data Removed</SPECIALTY>
              <LOCATION>Actual Data Removed</LOCATION>
              <ENTRY_DATE>Actual Data Removed</ENTRY_DATE>
              <ACTION>Actual Data Removed</ACTION>
          </DataTable>
      </NewDataSet>

      Comment

      • ShadowLocke
        New Member
        • Jan 2008
        • 116

        #4
        Im sorry jkmyoung..I got ahead of myself..you've already answered my problem here:


        I misinterpeted your solution.

        Comment

        Working...