473,761 Members | 10,684 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:styleshe et 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.d e/cdb.html"
xmlns:o="urn:sc hemas-microsoft-com:office:offi ce"
xmlns:x="urn:sc hemas-microsoft-com:office:exce l"
xmlns:ss="urn:s chemas-microsoft-com:office:spre adsheet"
xmlns:html="htt p://www.w3.org/TR/REC-html40">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="max_hiera rchy">
<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(a ncestor-or-self::xs:elemen t)"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="items" select="9"/>
<xsl:variable name="FirstItem Index" select="$max_hi erarchy * 2 +
1"/>
<xsl:variable name="ExpandedC olumnCount" select="$FirstI temIndex +
$items"/>
<xsl:variable name="Elements"
select="count(x s:schema/xs:element[@name='Chip']//xs:element)"/>
<!--header row counts -->
<xsl:variable name="ExpandedR owCount" select="$Elemen ts + 1"/>
<!-- <xsl:variable name="header_it ems"
select="documen t('<items><i>A</i><i>B</i></items>','/items'"-->
<Workbook xmlns="urn:sche mas-microsoft-com:office:spre adsheet"
xmlns:o="urn:sc hemas-microsoft-com:office:offi ce"
xmlns:x="urn:sc hemas-microsoft-com:office:exce l"
xmlns:ss="urn:s chemas-microsoft-com:office:spre adsheet"
xmlns:html="htt p://www.w3.org/TR/REC-html40">
<DocumentProper ties
namespace="urn: schemas-microsoft-com:office:offi ce">
<Author>CreateX LSXMLFromChipDB Schema</Author>
<LastAuthor>
<xsl:value-of select="//HISTORY//XSDHISTORY[last()]/@who"/>
</LastAuthor>
<Company>NEC Electronics (Europe)</Company>
</DocumentPropert ies>
<ExcelWorkboo k namespace="urn: schemas-microsoft-com:office:exce l">
<ProtectStructu re>False</ProtectStructur e>
<ProtectWindows >False</ProtectWindows>
</ExcelWorkbook>
<Styles>

snipped ..........

</Styles>
<Worksheet ss:Name="Schema Structure">
<Table ss:ExpandedRowC ount="{$Expande dRowCount + 100}"
ss:ExpandedColu mnCount="{$Expa ndedColumnCount }" x:FullColumns=" 0"
x:FullRows="1">
<!-- column widths -->
<Column ss:Index="{$Fir stItemIndex + 0}" ss:Width="20"/>
snipped ....
<Column ss:Index="{$Fir stItemIndex + 8}" ss:Width="100"/>
<!-- header line -->
<Row>
<Cell ss:MergeAccross ="{$FirstItemIn dex}"
ss:StyleID="hea der_element">
<Data ss:Type="String ">Hierarchy Element</Data>
</Cell>
<Cell ss:Index="{$Fir stItemIndex + 0}" ss:StyleID="hea der_item">
<Data ss:Type="String ">MinBound</Data>
</Cell>

snipped ......

<Cell ss:Index="{$Fir stItemIndex + 8}" ss:StyleID="hea der_item">
<Data ss:Type="String ">Example</Data>
</Cell>
</Row>
<Row><!-- this works well -->
<Cell ss:StyleID="Tre eLine">
<Data ss:Type="String ">├</Data>
</Cell>
</Row>
<!-- Rows inserted by the template get a null namespace with it
!!!1 -->
<xsl:apply-templates select="xs:sche ma/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:el ement">
<!-- Cell gets no additional namspace with it!! -->
<Cell ss:StyleID="Tre eLine">
<Data ss:Type="String ">│</Data>
</Cell>
</xsl:for-each>
<Cell ss:StyleID="Tre eLine">
<Data ss:Type="String ">├</Data>
</Cell>
<Cell ss:StyleID="Tre eLine">
<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:sche mas-microsoft-com:office:spre adsheet"
xmlns:cdb="http ://intra.etc.nec.d e/cdb.html"
xmlns:html="htt p://www.w3.org/TR/REC-html40"
xmlns:o="urn:sc hemas-microsoft-com:office:offi ce"
xmlns:ss="urn:s chemas-microsoft-com:office:spre adsheet"
xmlns:x="urn:sc hemas-microsoft-com:office:exce l"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<DocumentProper ties
namespace="urn: schemas-microsoft-com:office:offi ce">
<Author>CreateX LSXMLFromChipDB Schema</Author>
<LastAuthor>kem perr</LastAuthor>
<Company>NEC Electronics (Europe)</Company>
</DocumentPropert ies>
<ExcelWorkboo k namespace="urn: schemas-microsoft-com:office:exce l">
<ProtectStructu re>False</ProtectStructur e>
<ProtectWindows >False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal ">
<Alignment ss:Vertical="Bo ttom"/>
<Borders/>
<Font/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="header_e lement">
<Alignment ss:Horizontal=" Left" ss:Vertical="Bo ttom"/>
<Interior ss:Color="silve r" ss:Pattern="Sol id"/>
</Style>
<Style ss:ID="header_i tem">
<Alignment ss:Horizontal=" Left" ss:Vertical="Bo ttom"/>
</Style>
<Style ss:ID="element" >
<Alignment ss:Horizontal=" Left" ss:Vertical="Bo ttom"/>
<Interior ss:Color="orang e" ss:Pattern="Sol id"/>
</Style>
<Style ss:ID="leaf_ele ment">
<Alignment ss:Horizontal=" Left" ss:Vertical="Bo ttom"/>
<Interior ss:Color="blue" ss:Pattern="Sol id"/>
</Style>
<Style ss:ID="TreeLine ">
<Alignment ss:Horizontal=" Right" ss:Vertical="Bo ttom"/>
</Style>
</Styles>
<Worksheet ss:Name="Schema Structure">
<Table ss:ExpandedRowC ount="228" ss:ExpandedColu mnCount="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="hea der_element">
<Data ss:Type="String ">Hierarchy Element</Data>
</Cell>
<Cell ss:Index="13" ss:StyleID="hea der_item">
<Data ss:Type="String ">MinBound</Data>
</Cell>
<Cell ss:Index="14" ss:StyleID="hea der_item">
<Data ss:Type="String ">MaxBound</Data>
</Cell>
<Cell ss:Index="15" ss:StyleID="hea der_item">
<Data ss:Type="String ">ToolTip</Data>
</Cell>
<Cell ss:Index="16" ss:StyleID="hea der_item">
<Data ss:Type="String ">Help</Data>
</Cell>
<Cell ss:Index="17" ss:StyleID="hea der_item">
<Data ss:Type="String ">HierarchyName </Data>
</Cell>
<Cell ss:Index="18" ss:StyleID="hea der_item">
<Data ss:Type="String ">LeafChild </Data>
</Cell>
<Cell ss:Index="19" ss:StyleID="hea der_item">
<Data ss:Type="String ">FilterReg Ex</Data>
</Cell>
<Cell ss:Index="20" ss:StyleID="hea der_item">
<Data ss:Type="String ">FilterFun c</Data>
</Cell>
<Cell ss:Index="21" ss:StyleID="hea der_item">
<Data ss:Type="String ">Example</Data>
</Cell>
</Row>
<Row>
<Cell ss:StyleID="Tre eLine">
<Data ss:Type="String ">├</Data>
</Cell>
</Row>
<Row xmlns="">
<Cell ss:StyleID="Tre eLine">
<Data ss:Type="String ">├</Data>
</Cell>
<Cell ss:StyleID="Tre eLine">
<Data ss:Type="String ">Chip</Data>
</Cell>
</Row>
<Row xmlns="">
<Cell ss:StyleID="Tre eLine">
<Data ss:Type="String ">│</Data>
</Cell>
<Cell ss:StyleID="Tre eLine">
<Data ss:Type="String ">├</Data>
</Cell>
<Cell ss:StyleID="Tre eLine">
<Data ss:Type="String ">XMLHISTOR Y</Data>

snipped .....
############### ###### end ############### ##########
Jul 20 '05 #1
1 3279

<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:sche mas-microsoft-com:office:spre adsheet"

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

Solution, add

xmlns="urn:sche mas-microsoft-com:office:spre adsheet"
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:sche mas-microsoft-com:office:spre adsheet"
xmlns:o="urn:sc hemas-microsoft-com:office:offi ce"
xmlns:x="urn:sc hemas-microsoft-com:office:exce l"
xmlns:ss="urn:s chemas-microsoft-com:office:spre adsheet"
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
2318
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 same type for a given instance of the class, but different types for different instances.) #include<set> using namespace std; template<class T>
21
2103
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 doesn't seem to work. Here it is: #include <iostream> #include <cstdlib> using namespace std; template<int n>
13
1752
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
2622
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 an embedded environment with multiple processors. I created a policy for classes, which, I had hoped, would automatically register the class with the appropriate factory: // In some header file... #include <cassert>
3
2270
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 use this so that we can specify different templates to be used by the same xml node. Know that we could use global params, but would rather not have to update all teh stylesheets and any code that uses msxml and the same stylesheets.
2
2385
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> //So I can measure how long it take #include <complex> //Complex math suppor void fourn(complex <float> data, int nn, int ndim, int isign ...
4
5081
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() { return 0;
3
1372
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: gfield.h, gfield.cpp and main.c. ////////////////////////////////////// // gfield.h #pragma once #include <iostream> using namespace std;
7
5772
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 compiled no problem. But I can't find the what the problem is with templates? Please help. The main is in test-linked-list.cpp. There are two template classes. One is List1, the other one is ListNode. The codes are below: // test-linked-list.cpp :...
0
9521
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9333
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9765
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7324
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3863
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3442
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.