xsl-list
[Top] [All Lists]

[xsl] Transforming XML document to Microsoft Excel XML Format

2006-08-31 11:03:29
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 

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>