473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

template adds unexpected namespace

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: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">
<xsl:output 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: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
namespace="urn:schemas-microsoft-com:office:office">
<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:office: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:office:spreadsheet"
xmlns:cdb="http://intra.etc.nec.de/cdb.html"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<DocumentProperties
namespace="urn:schemas-microsoft-com:office:office">
<Author>CreateXLSXMLFromChipDBSchema</Author>
<LastAuthor>kemperr</LastAuthor>
<Company>NEC Electronics (Europe)</Company>
</DocumentProperties>
<ExcelWorkbook namespace="urn:schemas-microsoft-com:office: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:Pattern="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:Pattern="Solid"/>
</Style>
<Style ss:ID="leaf_element">
<Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>
<Interior ss:Color="blue" ss:Pattern="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 #########################
Jul 20 '05 #1
1 3238

<Row> <!-- here namespace xmlns="" is added as attribute
WHY ??? -->

Because at that point in the stylesheet the default namespace is
no-namespace so
<Row>
constructs an element with local name Row and namespace URI ""

But in the result tree the parent element has a namespace of

xmlns="urn:schemas-microsoft-com:office:spreadsheet"

so XSLT has to add xmlns="" to the start tag to keep Row in
no-namespace.

Solution, add

xmlns="urn:schemas-microsoft-com:office:spreadsheet"
to the current <Row> tag in teh stylesheet or more simply just move all
the namespace declarations that you want in the result xsl:stylesheet
element so that they are in scopr for your whole stylesheet ie move them
from
here:
<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"
which means they are only in scope inside the template for "/".

David
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Jon Wilson | last post by:
I have a class which needs to accumulate data. The way we get this data is by calling a member function which returns float on a number of different objects of different type (they are all the...
21
by: Protoman | last post by:
I've been looking at template metaprogramming. It seems really cool, make the compiler do most of the work. I have very simple program that uses TMP,it calculates the square of a number, but it...
13
by: Atlas | last post by:
Hi, I implemented a template as: template <int L, int M, int T> class Quantity { ..... public: friend Quantity operator*(const Quantity& q1,const Quantity& q2); ..... };
12
by: mlimber | last post by:
This is a repost (with slight modifications) from comp.lang.c++.moderated in an effort to get some response. I am using Loki's Factory as presented in _Modern C++ Design_ for message passing in...
3
by: Steve | last post by:
Is there any way of specifying the startMode when using the xslTransform class? We are updating code which used msxml to the system.xml classes but can find no way to specify the startMode. We...
2
by: Peter Cusack | last post by:
I'm getting error C2062: type 'float' unexpected and error C2065: 'complex' : undeclared identifier when I try to compile this #include "stdafx.h #include <iostream> //Consol I/ #include <time.h>...
4
by: Gary li | last post by:
Hi, all I find "template template" class cann't been compiled in VC6 but can ok in Redhat9. I write a test program like as: template< template<class> class T> class A { }; int main() {...
3
by: jianqi.wang | last post by:
Hi, everyone, I started learning C++ two weeks ago. I am trying to play with template with constant expressions for template. So I wrote a very simple program as follows... There are three files:...
7
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.