XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Remove leading Zeros from a st... (4)
-> + how to parse a html element fo... (2)
-> + Add namespaces to target messa... (2)
-> + XSLT Transformation - insertin... (3)
-> + Convert binary xml (9)
-> + XSLT Transformation (4)
-> + Generating hyperlinks (3)
-> + XSLT to PDF problem (with JAVA... (2)
-> + how to add onclick_ with try/c... (2)
-> + Keep table in one page. xsl-fo... (4)
-> + Cannot find a matching 2-argum... (3)
-> + Creating one string from a sub... (2)
-> + XSLT: Traversing XML twice for... (6)
-> + Copy element without namespace... (5)
-> + Create dynamic elemant name (2)
-> + XSLT: Traversing XML twice for... (3)
-> + Problem including Javascript (2)
-> + Looping through attributes (4)
-> + Transform values into elements... (4)
-> + Problem with deep node copy an... (2)
-> + Comparing Dates With ASP.NET 2... (3)
-> + Converting tree structure to h... (4)
-> + Attributes to element transfor... (2)
-> + XSLT transformation (2)
-> + XSLT transformation (5)
-> + xsl:character-map not working (2)
-> + Removing duplicates entries. (2)
-> + Image issues. (2)
-> + xsl transformation (4)
-> + XSL Question (5)
-> + how to insert xml file as an n... (2)
-> + Document Function (2)
-> + convert seconds to hh:mm:ss (5)
-> + how to remove attribute while ... (3)
-> + XSL-FO question (2)
-> + EDI 997 creation. (7)
-> + Line break within a tag in XML... (2)
-> + Contact Help Needed (2)
-> + ACK 997 (2)
-> + XSLT to output XML( which conf... (11)
-> + Retrieving all nodes where a c... (6)
-> + Verifying XML and XSD within X... (4)
-> + How to validate date format in... (3)
-> + XSLT question (2)
-> + Muenchian grouping (2)
-> + How to remove specific text en... (8)
-> + If Else Condition along with L... (2)
-> + SAXON Problem (2)
-> + comapring global variable valu... (2)
-> + copying the value of xsl in va... (2)
-> + Urgent:XSLT element value sel... (2)
-> + Ignoring first element using f... (2)
-> + EDI X12 to XML (4)
-> + XSLT FOR-EACH HELP (2)
-> + Sorting Help Needed (3)
-> + XSLT help with linking (2)
-> + selecting data into node set b... (2)
-> + Watch and Variable in Debug no... (4)
-> + Transforming XML to XML - grou... (2)
-> + Saxon 9.0 B support in debug m... (2)
-> + Repeating element question (2)
-> + Newly Purchased Version Not La... (2)
-> + xsl:include not finding file (5)
-> + JAXP and XSLT 2.0 / XPATH 2.0 (2)
-> + ASP:DropDownList trigger in Xs... (2)
-> + Auto-Skip empty values (2)
-> + retrieving a javascript functi... (2)
-> + need help (2)
-> + html tag ignored (2)
-> + Quick reply needed (8)
-> + xslt to remove namespaces but ... (2)
-> - Using a WSDL definition in an ... (1)
-> + XSL logic issue for simple inp... (6)
-> + Regarding XML namespace prefix... (4)
-> + Mapper reoganizes itself. (8)
-> + XSL Substring Removal (2)
-> + Regarding XSLT logic for a sim... (3)
-> + XSLT Transform documentation (2)
-> + XSLT stack trace in case of er... (3)
-> + No New Line (2)
-> - No New Line (1)
-> + howto loop through a sequence (2)
-> + xml and xsl and whitespace in... (2)
-> + XSL Date formatting (4)
-> + XSL to XSL Mapping using custo... (4)
-> + flat xml to nested xml comvers... (4)
-> + Including schema in scenario (2)
-> + DTDs and traversing (2)
-> + Help with transformation (2)
-> + Problem running XSLT against X... (2)
-> + Carriage return in the output (5)
-> + Generating XSLT to match a sch... (3)
-> + WYSIWYG editor (2)
-> + Grouping without For-Each (3)
-> + output XML using XSLT (8)
-> + Help configuring Xalan-j proce... (8)
-> + Convert Existing HTML pages to... (2)
-> + Generating Transformation - XS... (4)
-> + DOCTYPE public and system info... (2)
-> + Using EXSLT str:tokenize funct... (5)
-- Previous [661-680] [681-700] [701-720] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Gregory McKenzieSubject: Generate an XSLT from an XML file for subsequent use on other XML
Author: Gregory McKenzie
Date: 10 Oct 2007 11:55 AM
We are looking at taking an XML definition of a data table, generating an Excel XSLT from the XML definition of the data table. The generated Excel XSLT is then to be used on serialised data that is stored in the data table.

XML Definition of Data Table
----------------------------

Provided below is a cut down version of an XML definition of a table.

<SQLObjects>
<SQLObject Name="Delegate" ObjectType="tbl">
<Field Name="DelegateID" SQLType="int"/>
<Field Name="RecordedDate" SQLType="datetime"/>
</SQLObject>
</SQLObjects>


Generating an Excel XSLT from XML
---------------------------------

The Excel XSLT that we want to create takes the XML definition of the table and generates an XLST output that can then be used on XML data to output an Excel XML document. An example of the a cut down version of the Excel XSLT we are *trying to generate* is provided below.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:template match="ArrayOfConferenceDelegate">
<xsl:processing-instruction name="mso-application">
<xsl:text>progid="Excel.Sheet"</xsl:text>
</xsl:processing-instruction>
<Workbook>
<Worksheet ss:Name="Delegates">
<Table>
<Row ss:Index="1">
<Cell ss:Index="1">
<Data ss:Type="String">DelegateID</Data>
</Cell>
<Cell ss:Index="2">
<Data ss:Type="DateTime">RecordedDate</Data>
</Cell>
</Row>
<xsl:for-each select="Delegate">
<Row ss:Index="{position()+1}">
<Cell ss:Index="1">
<Data ss:Type="String">
<xsl:value-of select="DelegateID"/>
</Data>
</Cell>
<Cell ss:Index="2">
<Data ss:Type="String">
<xsl:value-of select="RecordedDate"/>
</Data>
</Cell>
</Row>
</xsl:for-each>
</Table>
</Worksheet>
</Workbook>
</xsl:template>
</xsl:stylesheet>


Applying Generated XSLT to XML
------------------------------

The generated Excel XSLT will then be applied to serialized data stored in the table. An example of the XML data on which the XSLT is applied is provided below.

<?xml version="1.0"?>
<ArrayOfDelegate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Delegate>
<DelegateID>1</DelegateID>
<RecordedDate>1900-01-01T00:00:00</RecordedDate>
</Delegate>
<Delegate>
<DelegateID>7</DelegateID>
<RecordedDate>1900-01-01T00:00:00</RecordedDate>
</Delegate>
</ArrayOfDelegate>

The XML above is transformed into an XML Excel document.


Issues
------

(A) Creating the XSLT that generates the Excel XSLT from the XML definition of the data table. The problems are outputting tags such as '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">'.

Have identified some useful commands along the was such as:

<xsl:processing-instruction name="mso-application">
<xsl:text>progid="Excel.Sheet"</xsl:text>
</xsl:processing-instruction>

but cannot work out how to generate all of the XSLT tags using XSLT.

(B) Namespace issues - the generated code has the Excel namespace tags on each of the tags generated.


Current XSLT that Generates Excel XSLT
--------------------------------------

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="/">
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Font ss:FontName="Arial" ss:Size="12"/>
</Style>
<Style ss:ID="Bold">
<Font ss:FontName="Arial" ss:Bold="1"/>
</Style>
<Style ss:ID="Date">
<NumberFormat ss:Format="yyyy\-mm\-dd\ hh:mm;@"/>
</Style>
</Styles>
<xsl:for-each select="SQLObjects/SQLObject">
<Worksheet ss:Name="{@Name}">
<Table>
<Row ss:Index="1">
<xsl:for-each select="Field[@SQLType!='uniqueidentifier']">
<Cell ss:Index="{position()}">
<Data ss:Type="String">
<xsl:value-of select="@Name"/>
</Data>
</Cell>
</xsl:for-each>
</Row>
<Row ss:Index="">
<xsl:for-each select="Field[@SQLType!='uniqueidentifier']">
<Cell ss:Index="">
<Data ss:Type="String">
<xsl:attribute name="xsl:value-of">
<xsl:text>select='</xsl:text><xsl:value-of select="@Name"/><xsl:text>'</xsl:text>
</xsl:attribute>
</Data>
</Cell>
</xsl:for-each>
</Row>
</Table>
</Worksheet>
</xsl:for-each>
</Workbook>
</xsl:template>
</xsl:stylesheet>


Current Excel XSLT Generated from XSLT
--------------------------------------

<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<Styles xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<Style ss:ID="Default" ss:Name="Normal" xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<Font ss:FontName="Arial" ss:Size="12" xmlns="urn:schemas-microsoft-com:office:spreadsheet"/>
</Style>
<Style ss:ID="Bold" xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<Font ss:FontName="Arial" ss:Bold="1" xmlns="urn:schemas-microsoft-com:office:spreadsheet"/>
</Style>
<Style ss:ID="Date" xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<NumberFormat ss:Format="yyyy\-mm\-dd\ hh:mm;@" xmlns="urn:schemas-microsoft-com:office:spreadsheet"/>
</Style>
</Styles>
<Worksheet ss:Name="ConferenceDelegate" xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<Table xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<Row ss:Index="1" xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<Cell ss:Index="1" xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<Data ss:Type="String" xmlns="urn:schemas-microsoft-com:office:spreadsheet">DelegateID</Data>
</Cell>
<Cell ss:Index="2" xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<Data ss:Type="String" xmlns="urn:schemas-microsoft-com:office:spreadsheet">RecordedDate</Data>
</Cell>
</Row>
<Row ss:Index="" xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<Cell ss:Index="" xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<Data ss:Type="String" xmlns="urn:schemas-microsoft-com:office:spreadsheet" xsl:value-of="select='DelegateID'"/>
</Cell>
<Cell ss:Index="" xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<Data ss:Type="String" xmlns="urn:schemas-microsoft-com:office:spreadsheet" xsl:value-of="select='RecordedDate'"/>
</Cell>
</Row>
</Table>
</Worksheet>
</Workbook>


Best Way Forward?
-----------------

Should we change our output method to TEXT instead of XML and generate the Excel XSLT that way. Alternatively, does somebody have an example of how we can use XSLT to generate XLST from XML?

Posttop
(Deleted User) Subject: Generate an XSLT from an XML file for subsequent use on other XML
Author: (Deleted User)
Date: 10 Oct 2007 12:30 PM
Hi Gregory,
what you are trying to do is called "meta stylesheet", where an XSLT stylesheet has as output another XSLT stylesheet. The trick to make it work is to generate the XSLT keywords in a different namespace (like out:stylesheet, with "out" assigned to the "xxxxx" namespace URI), and then have a xsl:namespace-alias instruction to convert it to the real one.
See http://www.xml.com/pub/a/2003/11/05/xslt.html for a nuce tutorial on this technique.

Hope this helps,
Alberto

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.