[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Transforming XML document to Microsoft Excel XML Forma

Subject: Transforming XML document to Microsoft Excel XML Format
From: Tom Sawyer <z0n0mail@xxxxxxxxx>
Date: Thu, 31 Aug 2006 10:13:01 -0700 (PDT)
xml forma
Hi,

   I m a xml/xslt newbie working to transform an xml
document to an MS-Excel xml format. I am having issues
creating an element with an attribute, marked in the
xsl file with "PROBLEM HERE". I need to have the
attribute of the "roster_report" element be included
in the ss:Name attribute value of the Worksheet tag
for the output, and it blows up when I use the xsl
I've specified.

Can someone please help me out how to do it the right
way ? Please help !

-Tom



I am including the  input xml 
==================
INPUT XML
==================
<?xml version="1.0" encoding="UTF-8"?>
<reports>
  <group_report id="Group Id" title="Group Title">
    <roster_report id="ReportIdOne">
      <title>ReportOne Title</title>
      <data_row>
        <row_header>HeaderContent One</row_header>
        <data>a</data>
      </data_row>
      <data_row>
        <row_header>HeaderContent Two</row_header>
        <data>b</data>
      </data_row>
      <data_row>
        <row_header>HeaderContent Three</row_header>
        <data>c</data>
      </data_row>
      </roster_report>
    <roster_report id="ReportIdTwo">
      <title>ReportTwo Title</title>
      <data_row>
        <row_header>HeaderContent One</row_header>
        <data>a</data>
      </data_row>
      <data_row>
        <row_header>HeaderContent Two</row_header>
        <data>b</data>
      </data_row>
      <data_row>
        <row_header>HeaderContent Three</row_header>
        <data>c</data>
      </data_row>
      </roster_report>
  </group>
</reports>


============================
DESIRED OUTPUT XML (Microsoft Excel)
============================
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<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">
 <DocumentProperties
xmlns="urn:schemas-microsoft-com:office:office">
  <Author>authName</Author>
  <LastAuthor>authName</LastAuthor>
  <Created>datestamp</Created>
  <LastSaved>datestamp</LastSaved>
  <Company>CompanyName</Company>
  <Version>11.8036</Version>
 </DocumentProperties>
 <ExcelWorkbook
xmlns="urn:schemas-microsoft-com:office:excel">
  <WindowHeight>13545</WindowHeight>
  <WindowWidth>19035</WindowWidth>
  <WindowTopX>240</WindowTopX>
  <WindowTopY>30</WindowTopY>
  <ActiveSheet>1</ActiveSheet>
  <ProtectStructure>False</ProtectStructure>
  <ProtectWindows>False</ProtectWindows>
 </ExcelWorkbook>
 <!--
 ..
 ..
 -->
 <Worksheet ss:Name="ReportIdOne">
   <Table ss:ExpandedColumnCount="2"
ss:ExpandedRowCount="3" x:FullColumns="1"
    x:FullRows="1">
    <Row>
     <Cell><Data ss:Type="String">HeaderContent
One</Data></Cell>
     <Cell><Data ss:Type="String">a</Data></Cell>
    </Row>
    <Row>
     <Cell><Data ss:Type="String">HeaderContent
Two</Data></Cell>
     <Cell><Data ss:Type="String">b</Data></Cell>
    </Row>
    <Row>
     <Cell><Data ss:Type="String">HeaderContent
Three</Data></Cell>
     <Cell><Data ss:Type="String">c</Data></Cell>
    </Row>
   </Table>
   <WorksheetOptions
xmlns="urn:schemas-microsoft-com:office:excel">
    <Panes>
     <Pane>
      <Number>1</Number>
      <ActiveRow>1</ActiveRow>
      <RangeSelection>R2:R3</RangeSelection>
     </Pane>
    </Panes>
    <ProtectObjects>False</ProtectObjects>
    <ProtectScenarios>False</ProtectScenarios>
   </WorksheetOptions>
  </Worksheet>
<!--
  Repeat for 2nd, 3rd.. n workseets (each worksheet
for a roster_report)
  ..
  -->
  </Workbook>
  
  
  
  
  
  
  ================
  XSL stylesheet used
  ================
  <?xml version="1.0" encoding="UTF-8" ?>
  <xsl:stylesheet version="1.0"
                 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  >
  	<xsl:output method="xml"/>
  
  	<xsl:template match="reports">
  			<Workbook
xmlns="urn:schemas-microsoft-com:office:spreadsheet" 
  		
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
   <DocumentProperties
xmlns="urn:schemas-microsoft-com:office:office">
    <Author>authName</Author>
    <LastAuthor>authName</LastAuthor>
    <Created>datestamp</Created>
    <LastSaved>datestamp</LastSaved>
    <Company>CompanyName</Company>
    <Version>11.8036</Version>
   </DocumentProperties>
   <ExcelWorkbook
xmlns="urn:schemas-microsoft-com:office:excel">
    <WindowHeight>13545</WindowHeight>
    <WindowWidth>19035</WindowWidth>
    <WindowTopX>240</WindowTopX>
    <WindowTopY>30</WindowTopY>
    <ActiveSheet>1</ActiveSheet>
    <ProtectStructure>False</ProtectStructure>
    <ProtectWindows>False</ProtectWindows>
   </ExcelWorkbook>
  <!--
   ..
   ..
   -->
  	<xsl:for-each select="//roster_report">  
  
  
  			<Worksheet ss:Name='<xsl:value-of
select="@id"/>'>    <!-- PROBLEM HERE -->
     <Table ss:ExpandedColumnCount="2"
ss:ExpandedRowCount="3" x:FullColumns="1"
      x:FullRows="1">
      <Row>
       <Cell><Data ss:Type="String">HeaderContent
One</Data></Cell>
       <Cell><Data ss:Type="String">a</Data></Cell>
      </Row>
      <Row>
       <Cell><Data ss:Type="String">HeaderContent
Two</Data></Cell>
       <Cell><Data ss:Type="String">b</Data></Cell>
      </Row>
      <Row>
       <Cell><Data ss:Type="String">HeaderContent
Three</Data></Cell>
       <Cell><Data ss:Type="String">c</Data></Cell>
      </Row>
     </Table>
  				<WorksheetOptions
xmlns="urn:schemas-microsoft-com:office:excel">
  					<Panes>
  						<Pane>
  							<Number>1</Number>
  							<ActiveRow>1</ActiveRow>
  							<RangeSelection>R2:R3</RangeSelection>
  						</Pane>
  					</Panes>
  					<ProtectObjects>False</ProtectObjects>
  					<ProtectScenarios>False</ProtectScenarios>
  				</WorksheetOptions>
  			</Worksheet>
  
  			
   		</xsl:for-each>   
  		</Workbook>
  	</xsl:template>
  
  </xsl:stylesheet>


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.