R
Rolf Kemper
Dear Experts,
I'm going to create an Excell spreadsheet xml. So far things work very
well. But in case I add <Row> elements by a recursive template call it
goes wrong.
See the attached XSLT and the result. Last 30 lines of the xslt may be
the most interesting ones. I'm processing it with XMLSPY. Regardless
of the xslt processor (ALTOVA / MSXML4 ) I get the same result.
Hence, I belive I have not done it right. Sorry for the long code, but
I do not really know where the problem might be.
Any help is welcome
Regards
Rolf
######################### XSLT ###################################
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:cdb="http://intra.etc.nec.de/cdb.html"
xmlns
="urn:schemas-microsoft-com
ffice
ffice"
xmlns:x="urn:schemas-microsoft-com
ffice:excel"
xmlns:ss="urn:schemas-microsoft-com
ffice:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<xsl
utput method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="max_hierarchy">
<xsl:for-each select="//xs:element">
<xsl:sort select="-count(ancestor::xs:element)"
data-type="number"/>
<xsl:if test="position()=1">
<xsl:value-of select="count(ancestor-or-self::xs:element)"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="items" select="9"/>
<xsl:variable name="FirstItemIndex" select="$max_hierarchy * 2 +
1"/>
<xsl:variable name="ExpandedColumnCount" select="$FirstItemIndex +
$items"/>
<xsl:variable name="Elements"
select="count(xs:schema/xs:element[@name='Chip']//xs:element)"/>
<!--header row counts -->
<xsl:variable name="ExpandedRowCount" select="$Elements + 1"/>
<!-- <xsl:variable name="header_items"
select="document('<items><i>A</i><i>B</i></items>','/items'"-->
<Workbook xmlns="urn:schemas-microsoft-com
ffice:spreadsheet"
xmlns
="urn:schemas-microsoft-com
ffice
ffice"
xmlns:x="urn:schemas-microsoft-com
ffice:excel"
xmlns:ss="urn:schemas-microsoft-com
ffice:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties
namespace="urn:schemas-microsoft-com
ffice
ffice">
<Author>CreateXLSXMLFromChipDBSchema</Author>
<LastAuthor>
<xsl:value-of select="//HISTORY//XSDHISTORY[last()]/@who"/>
</LastAuthor>
<Company>NEC Electronics (Europe)</Company>
</DocumentProperties>
<ExcelWorkbook namespace="urn:schemas-microsoft-com
ffice:excel">
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
snipped ..........
</Styles>
<Worksheet ss:Name="SchemaStructure">
<Table ss:ExpandedRowCount="{$ExpandedRowCount + 100}"
ss:ExpandedColumnCount="{$ExpandedColumnCount}" x:FullColumns="0"
x:FullRows="1">
<!-- column widths -->
<Column ss:Index="{$FirstItemIndex + 0}" ss:Width="20"/>
snipped ....
<Column ss:Index="{$FirstItemIndex + 8}" ss:Width="100"/>
<!-- header line -->
<Row>
<Cell ss:MergeAccross="{$FirstItemIndex}"
ss:StyleID="header_element">
<Data ss:Type="String">Hierarchy Element</Data>
</Cell>
<Cell ss:Index="{$FirstItemIndex + 0}" ss:StyleID="header_item">
<Data ss:Type="String">MinBound</Data>
</Cell>
snipped ......
<Cell ss:Index="{$FirstItemIndex + 8}" ss:StyleID="header_item">
<Data ss:Type="String">Example</Data>
</Cell>
</Row>
<Row><!-- this works well -->
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">├</Data>
</Cell>
</Row>
<!-- Rows inserted by the template get a null namespace with it
!!!1 -->
<xsl:apply-templates select="xs:schema/xs:element[@name='Chip']"
mode="e"/>
</Table>
</Worksheet>
</Workbook>
</xsl:template>
<xsl:template match="*" mode="e">
<!--<xsl:element name="Row"> the same behaviour as <Row> -->
<Row> <!-- here namespace xmlns="" is added as attribute WHY ??? -->
<xsl:for-each select="./ancestor::xs:element">
<!-- Cell gets no additional namspace with it!! -->
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">│</Data>
</Cell>
</xsl:for-each>
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">├</Data>
</Cell>
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">
<xsl:value-of select="@name"/>
</Data>
</Cell>
</Row>
<xsl:apply-templates
select="./xs:complexType/xs:sequence/xs:element" mode="e"/>
</xsl:template>
</xsl:stylesheet>
############## RESULT ##############################
<?xml version="1.0" encoding="UTF-8"?>
<Workbook xmlns="urn:schemas-microsoft-com
ffice:spreadsheet"
xmlns:cdb="http://intra.etc.nec.de/cdb.html"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns
="urn:schemas-microsoft-com
ffice
ffice"
xmlns:ss="urn:schemas-microsoft-com
ffice:spreadsheet"
xmlns:x="urn:schemas-microsoft-com
ffice:excel"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<DocumentProperties
namespace="urn:schemas-microsoft-com
ffice
ffice">
<Author>CreateXLSXMLFromChipDBSchema</Author>
<LastAuthor>kemperr</LastAuthor>
<Company>NEC Electronics (Europe)</Company>
</DocumentProperties>
<ExcelWorkbook namespace="urn:schemas-microsoft-com
ffice:excel">
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="header_element">
<Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>
<Interior ss:Color="silver" ss
attern="Solid"/>
</Style>
<Style ss:ID="header_item">
<Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>
</Style>
<Style ss:ID="element">
<Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>
<Interior ss:Color="orange" ss
attern="Solid"/>
</Style>
<Style ss:ID="leaf_element">
<Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>
<Interior ss:Color="blue" ss
attern="Solid"/>
</Style>
<Style ss:ID="TreeLine">
<Alignment ss:Horizontal="Right" ss:Vertical="Bottom"/>
</Style>
</Styles>
<Worksheet ss:Name="SchemaStructure">
<Table ss:ExpandedRowCount="228" ss:ExpandedColumnCount="22"
x:FullColumns="0" x:FullRows="1">
<Column ss:Index="13" ss:Width="20"/>
<Column ss:Index="14" ss:Width="20"/>
<Column ss:Index="15" ss:Width="100"/>
<Column ss:Index="16" ss:Width="100"/>
<Column ss:Index="17" ss:Width="30"/>
<Column ss:Index="18" ss:Width="30"/>
<Column ss:Index="19" ss:Width="100"/>
<Column ss:Index="20" ss:Width="100"/>
<Column ss:Index="21" ss:Width="100"/>
<Row>
<Cell ss:MergeAccross="13" ss:StyleID="header_element">
<Data ss:Type="String">Hierarchy Element</Data>
</Cell>
<Cell ss:Index="13" ss:StyleID="header_item">
<Data ss:Type="String">MinBound</Data>
</Cell>
<Cell ss:Index="14" ss:StyleID="header_item">
<Data ss:Type="String">MaxBound</Data>
</Cell>
<Cell ss:Index="15" ss:StyleID="header_item">
<Data ss:Type="String">ToolTip</Data>
</Cell>
<Cell ss:Index="16" ss:StyleID="header_item">
<Data ss:Type="String">Help</Data>
</Cell>
<Cell ss:Index="17" ss:StyleID="header_item">
<Data ss:Type="String">HierarchyName</Data>
</Cell>
<Cell ss:Index="18" ss:StyleID="header_item">
<Data ss:Type="String">LeafChild</Data>
</Cell>
<Cell ss:Index="19" ss:StyleID="header_item">
<Data ss:Type="String">FilterRegEx</Data>
</Cell>
<Cell ss:Index="20" ss:StyleID="header_item">
<Data ss:Type="String">FilterFunc</Data>
</Cell>
<Cell ss:Index="21" ss:StyleID="header_item">
<Data ss:Type="String">Example</Data>
</Cell>
</Row>
<Row>
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">├</Data>
</Cell>
</Row>
<Row xmlns="">
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">├</Data>
</Cell>
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">Chip</Data>
</Cell>
</Row>
<Row xmlns="">
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">│</Data>
</Cell>
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">├</Data>
</Cell>
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">XMLHISTORY</Data>
snipped .....
##################### end #########################
I'm going to create an Excell spreadsheet xml. So far things work very
well. But in case I add <Row> elements by a recursive template call it
goes wrong.
See the attached XSLT and the result. Last 30 lines of the xslt may be
the most interesting ones. I'm processing it with XMLSPY. Regardless
of the xslt processor (ALTOVA / MSXML4 ) I get the same result.
Hence, I belive I have not done it right. Sorry for the long code, but
I do not really know where the problem might be.
Any help is welcome
Regards
Rolf
######################### XSLT ###################################
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:cdb="http://intra.etc.nec.de/cdb.html"
xmlns
xmlns:x="urn:schemas-microsoft-com
xmlns:ss="urn:schemas-microsoft-com
xmlns:html="http://www.w3.org/TR/REC-html40">
<xsl
<xsl:template match="/">
<xsl:variable name="max_hierarchy">
<xsl:for-each select="//xs:element">
<xsl:sort select="-count(ancestor::xs:element)"
data-type="number"/>
<xsl:if test="position()=1">
<xsl:value-of select="count(ancestor-or-self::xs:element)"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="items" select="9"/>
<xsl:variable name="FirstItemIndex" select="$max_hierarchy * 2 +
1"/>
<xsl:variable name="ExpandedColumnCount" select="$FirstItemIndex +
$items"/>
<xsl:variable name="Elements"
select="count(xs:schema/xs:element[@name='Chip']//xs:element)"/>
<!--header row counts -->
<xsl:variable name="ExpandedRowCount" select="$Elements + 1"/>
<!-- <xsl:variable name="header_items"
select="document('<items><i>A</i><i>B</i></items>','/items'"-->
<Workbook xmlns="urn:schemas-microsoft-com
xmlns
xmlns:x="urn:schemas-microsoft-com
xmlns:ss="urn:schemas-microsoft-com
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties
namespace="urn:schemas-microsoft-com
<Author>CreateXLSXMLFromChipDBSchema</Author>
<LastAuthor>
<xsl:value-of select="//HISTORY//XSDHISTORY[last()]/@who"/>
</LastAuthor>
<Company>NEC Electronics (Europe)</Company>
</DocumentProperties>
<ExcelWorkbook namespace="urn:schemas-microsoft-com
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
snipped ..........
</Styles>
<Worksheet ss:Name="SchemaStructure">
<Table ss:ExpandedRowCount="{$ExpandedRowCount + 100}"
ss:ExpandedColumnCount="{$ExpandedColumnCount}" x:FullColumns="0"
x:FullRows="1">
<!-- column widths -->
<Column ss:Index="{$FirstItemIndex + 0}" ss:Width="20"/>
snipped ....
<Column ss:Index="{$FirstItemIndex + 8}" ss:Width="100"/>
<!-- header line -->
<Row>
<Cell ss:MergeAccross="{$FirstItemIndex}"
ss:StyleID="header_element">
<Data ss:Type="String">Hierarchy Element</Data>
</Cell>
<Cell ss:Index="{$FirstItemIndex + 0}" ss:StyleID="header_item">
<Data ss:Type="String">MinBound</Data>
</Cell>
snipped ......
<Cell ss:Index="{$FirstItemIndex + 8}" ss:StyleID="header_item">
<Data ss:Type="String">Example</Data>
</Cell>
</Row>
<Row><!-- this works well -->
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">├</Data>
</Cell>
</Row>
<!-- Rows inserted by the template get a null namespace with it
!!!1 -->
<xsl:apply-templates select="xs:schema/xs:element[@name='Chip']"
mode="e"/>
</Table>
</Worksheet>
</Workbook>
</xsl:template>
<xsl:template match="*" mode="e">
<!--<xsl:element name="Row"> the same behaviour as <Row> -->
<Row> <!-- here namespace xmlns="" is added as attribute WHY ??? -->
<xsl:for-each select="./ancestor::xs:element">
<!-- Cell gets no additional namspace with it!! -->
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">│</Data>
</Cell>
</xsl:for-each>
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">├</Data>
</Cell>
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">
<xsl:value-of select="@name"/>
</Data>
</Cell>
</Row>
<xsl:apply-templates
select="./xs:complexType/xs:sequence/xs:element" mode="e"/>
</xsl:template>
</xsl:stylesheet>
############## RESULT ##############################
<?xml version="1.0" encoding="UTF-8"?>
<Workbook xmlns="urn:schemas-microsoft-com
xmlns:cdb="http://intra.etc.nec.de/cdb.html"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns
xmlns:ss="urn:schemas-microsoft-com
xmlns:x="urn:schemas-microsoft-com
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<DocumentProperties
namespace="urn:schemas-microsoft-com
<Author>CreateXLSXMLFromChipDBSchema</Author>
<LastAuthor>kemperr</LastAuthor>
<Company>NEC Electronics (Europe)</Company>
</DocumentProperties>
<ExcelWorkbook namespace="urn:schemas-microsoft-com
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="header_element">
<Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>
<Interior ss:Color="silver" ss
</Style>
<Style ss:ID="header_item">
<Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>
</Style>
<Style ss:ID="element">
<Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>
<Interior ss:Color="orange" ss
</Style>
<Style ss:ID="leaf_element">
<Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>
<Interior ss:Color="blue" ss
</Style>
<Style ss:ID="TreeLine">
<Alignment ss:Horizontal="Right" ss:Vertical="Bottom"/>
</Style>
</Styles>
<Worksheet ss:Name="SchemaStructure">
<Table ss:ExpandedRowCount="228" ss:ExpandedColumnCount="22"
x:FullColumns="0" x:FullRows="1">
<Column ss:Index="13" ss:Width="20"/>
<Column ss:Index="14" ss:Width="20"/>
<Column ss:Index="15" ss:Width="100"/>
<Column ss:Index="16" ss:Width="100"/>
<Column ss:Index="17" ss:Width="30"/>
<Column ss:Index="18" ss:Width="30"/>
<Column ss:Index="19" ss:Width="100"/>
<Column ss:Index="20" ss:Width="100"/>
<Column ss:Index="21" ss:Width="100"/>
<Row>
<Cell ss:MergeAccross="13" ss:StyleID="header_element">
<Data ss:Type="String">Hierarchy Element</Data>
</Cell>
<Cell ss:Index="13" ss:StyleID="header_item">
<Data ss:Type="String">MinBound</Data>
</Cell>
<Cell ss:Index="14" ss:StyleID="header_item">
<Data ss:Type="String">MaxBound</Data>
</Cell>
<Cell ss:Index="15" ss:StyleID="header_item">
<Data ss:Type="String">ToolTip</Data>
</Cell>
<Cell ss:Index="16" ss:StyleID="header_item">
<Data ss:Type="String">Help</Data>
</Cell>
<Cell ss:Index="17" ss:StyleID="header_item">
<Data ss:Type="String">HierarchyName</Data>
</Cell>
<Cell ss:Index="18" ss:StyleID="header_item">
<Data ss:Type="String">LeafChild</Data>
</Cell>
<Cell ss:Index="19" ss:StyleID="header_item">
<Data ss:Type="String">FilterRegEx</Data>
</Cell>
<Cell ss:Index="20" ss:StyleID="header_item">
<Data ss:Type="String">FilterFunc</Data>
</Cell>
<Cell ss:Index="21" ss:StyleID="header_item">
<Data ss:Type="String">Example</Data>
</Cell>
</Row>
<Row>
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">├</Data>
</Cell>
</Row>
<Row xmlns="">
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">├</Data>
</Cell>
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">Chip</Data>
</Cell>
</Row>
<Row xmlns="">
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">│</Data>
</Cell>
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">├</Data>
</Cell>
<Cell ss:StyleID="TreeLine">
<Data ss:Type="String">XMLHISTORY</Data>
snipped .....
##################### end #########################