Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 8th, 2008, 09:57 AM
Registered User
 
Join Date: May 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL for Excel

I have created this stylesheet for XML source. But when i open the excel sheet it displays the rows as colummns. what am i doing wrong. please help.

<?xml version="1.0" ?>
<ROWSET>
    <ROW>
                <EMAIL_ADDRESS>[email protected]</EMAIL_ADDRESS>
                <FULL_NAME>Brookes, Allan</FULL_NAME>
                <AMOUNT_LIMIT>200000</AMOUNT_LIMIT>
    </ROW>
    <ROW>
     <EMAIL_ADDRESS>[email protected]</EMAIL_ADDRESS>
     <FULL_NAME>Brookes, Allan</FULL_NAME>
     <AMOUNT_LIMIT>50000</AMOUNT_LIMIT>
    </ROW>
    <ROW>
         <EMAIL_ADDRESS>[email protected]</EMAIL_ADDRESS>
     <FULL_NAME>Born, Martha</FULL_NAME>
     <AMOUNT_LIMIT>25000</AMOUNT_LIMIT>
    </ROW>
</ROWSET>

in the excel sheet it displays like this

ns1:Name Data ns1:Type
HR_Hierarchy_feed_to_CT_ [email protected] String
Hierarchy_feed_to_CT_ Brookes, Allan String
HR_Hierarchy_feed_to_CT_ 200000 Number
HR_Hierarchy_feed_to_CT_ [email protected] String
HR_Hierarchy_feed_to_CT_ Brookes, Allan String
HR_Hierarchy_feed_to_CT_ 50000 Number
HR_Hierarchy_feed_to_CT_ [email protected] String
HR_Hierarchy_feed_to_CT_ Born, Martha String
HR_Hierarchy_feed_to_CT_ 25000 Number

I want it like this
[email protected] Brookes, Allan 200000
[email protected] Brookes, Allan 50000
[email protected] Born, Martha 25000


XSL Stylesheet

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel">
<xsl:template match="/">
<Workbook>
<Worksheet ss:Name="HR_Hierarchy_feed_to_CT_">
  <Table>
<xsl:for-each select="ROWSET/ROW">
<ROW>

  <Cell>
            <Data ss:Type="String">
<xsl:value-of select="EMAIL_ADDRESS"/>
</Data>
        </Cell>

 <Cell>
            <Data ss:Type="String">
<xsl:value-of select="FULL_NAME"/>
</Data>
        </Cell>

<Cell>
            <Data ss:Type="Number">
<xsl:value-of select="AMOUNT_LIMIT"/>
</Data>
 </Cell>

</ROW>
</xsl:for-each>
</Table>
</Worksheet>
</Workbook>
</xsl:template>
</xsl:stylesheet>
 
Old May 8th, 2008, 11:46 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I am not particular familiar with the Excel XML format but an example I have here has most elements in the namespace urn:schemas-microsoft-com:office:spreadsheet so you need e.g.
Code:
<xsl:stylesheet version="1.0"
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel">
and then with XML tag names are case-sensitive so use
Code:
<Row>
...
</Row>
for the Excel Row elements.


--
  Martin Honnen
  Microsoft MVP - XML
 
Old May 8th, 2008, 12:23 PM
Registered User
 
Join Date: May 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I changed the <ROW> tags to <Row> but i got the same output.



 
Old May 8th, 2008, 12:27 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Did you change the namespace as well?

--
  Martin Honnen
  Microsoft MVP - XML
 
Old May 8th, 2008, 12:58 PM
Registered User
 
Join Date: May 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I changed the namespace then it worked. Thanks very much.
what is the difference in my namespace and the one you have given?

 
Old May 9th, 2008, 05:31 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Their is no difference in the namespace itself, rather where it is applied to.
With xmlns="urn:schemas-microsoft-com:office:spreadsheet" it is the default namespace to be applied to all elements that don't have a prefix in their name.
With xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" it only applies to attributes and elements having the prefix 'ss' in their name.
So to make sure the Workbook, Worksheet and other elements are in the Excel namespace urn:schemas-microsoft-com:office:spreadsheet you need a default namespace declaration. Or you would need to qualify all elements with the prefix 'ss' e.g. ss:Workbook.

--
  Martin Honnen
  Microsoft MVP - XML





Similar Threads
Thread Thread Starter Forum Replies Last Post
problems with excel generated usng xsl a_gomathi XSLT 5 May 29th, 2008 01:30 PM
XSL DateTime format for Excel fmoon606 XSLT 8 May 23rd, 2008 05:35 PM
xsl:param and xsl:apply-templates' "select" newbieboobers XSLT 1 March 25th, 2008 07:23 PM
Pass link values as xsl:parameter to php5 then xsl pauljr8 XSLT 1 July 2nd, 2007 10:32 PM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.