473,322 Members | 1,781 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,322 software developers and data experts.

Need help inserting namespace

CB
I have a group of documents that previously had no schema, now I have
a schema, and I want to use XSLT to fixup the documents by inserting
the namespace reference.

In other words, my input document looks like

<SiteAdaptationFile>
...
</SiteAdaptationFile>

and I'm looking for output like

<SiteAdaptationFile xmlns="http://www.sensis.com/AdaptSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sensis.com/AdaptSchema IddAdapt.xsd">
...
</SiteAdaptationFile>

Here is my xslt script. The foo attribute is just a dummy, and I
put it in because Xalan complains about the other attribute names,
and ignores them. i.e., i wanted to see something change.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>

<xsl:template match="/">
<xsl:apply-templates select="SiteAdaptationFile"/>
</xsl:template>

<xsl:template match="SiteAdaptationFile">
<xsl:element name="SiteAdaptationFile">
<xsl:attribute name="foo" >
<xsl:text>bar</xsl:text>
</xsl:attribute>
<xsl:attribute name="xmlns" >
<xsl:text>http://www.sensis.com/AdaptSchema</xsl:text>
</xsl:attribute>
<xsl:attribute name="xmlns:xsi" >
<xsl:text>http://www.w3.org/2001/XMLSchema-instance</xsl:text>
</xsl:attribute>
<xsl:attribute name="xsi:schemaLocation" >
<xsl:text>http://www.sensis.com/AdaptSchema
IddAdapt.xsd</xsl:text>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

My actual output is

<SiteAdaptationFile foo="bar">
...
</SiteAdaptationFile>

I'm sure my question exposes my ignorance of XSLT, and I appreciate
any help, very much.
Jul 20 '05 #1
1 2258
"CB" <cb****@sensis.com> schrieb im Newsbeitrag
news:40**************************@posting.google.c om...
I have a group of documents that previously had no schema, now I have
a schema, and I want to use XSLT to fixup the documents by inserting
the namespace reference.

In other words, my input document looks like

<SiteAdaptationFile>
...
</SiteAdaptationFile>

and I'm looking for output like

<SiteAdaptationFile xmlns="http://www.sensis.com/AdaptSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sensis.com/AdaptSchema IddAdapt.xsd">
...
</SiteAdaptationFile>

Here is my xslt script. The foo attribute is just a dummy, and I
put it in because Xalan complains about the other attribute names,
and ignores them. i.e., i wanted to see something change.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>

<xsl:template match="/">
<xsl:apply-templates select="SiteAdaptationFile"/>
</xsl:template>

<xsl:template match="SiteAdaptationFile">
<xsl:element name="SiteAdaptationFile">
<xsl:attribute name="foo" >
<xsl:text>bar</xsl:text>
</xsl:attribute>
<xsl:attribute name="xmlns" >
<xsl:text>http://www.sensis.com/AdaptSchema</xsl:text>
</xsl:attribute>
<xsl:attribute name="xmlns:xsi" >
<xsl:text>http://www.w3.org/2001/XMLSchema-instance</xsl:text>
</xsl:attribute>
<xsl:attribute name="xsi:schemaLocation" >
<xsl:text>http://www.sensis.com/AdaptSchema
IddAdapt.xsd</xsl:text>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

My actual output is

<SiteAdaptationFile foo="bar">
...
</SiteAdaptationFile>

I'm sure my question exposes my ignorance of XSLT, and I appreciate
any help, very much.


XSLT doesn't treat namespace declarions as attributes.

Just do something like:

<xsl:template match="SiteAdaptationFile">
<SiteAdaptationFile xmlns="http://www.sensis.com/AdaptSchema">
<xsl:apply-templates/>
</SiteAdaptionFile>
</xsl:template>
Jul 20 '05 #2

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

Similar topics

3
by: jwalton | last post by:
This is so silly I must be doing something wrong! I need to insert (using VB.NET) a new node in a DOM; node has a namespace. I first create, under programme, basic structure, starting thus: ...
10
by: Ryan Graham | last post by:
I totally bombed this question in an interview so I'm posting my answer here for comments and suggestions... perhaps (god help me) I'm just not that bright, but this works and seems to be fairly...
1
by: Kevin | last post by:
Hello experts, I'm a newbee to ASP.NET. And I have been struggling solving this problem. But I can't do it. Can you please help me get over this wall? Below is the code and error message: <%@...
2
by: altergothen | last post by:
Hi there I am a newbie to ASP.Net - Please Help! I am trying to insert the values of my variables into a database. If I try the following it works perfectly: string insertQuery = "INSERT into...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
0
by: pd123 | last post by:
I'm new to C# and .net and I'm trying to create a form that will register users in a sql server database. I have the following code but when I run the code I get an error " The name 'Peter' is...
4
by: orel | last post by:
<o_r_l_25@yahoo.frwrote, As the message says, to help the compiler with template parsing, I add 'typename' as you said, it now understands the expression, but but i have now those complier...
0
by: R. Ian Lee | last post by:
I've built an XSLT file that transforms data to SpreadsheetML format. The XSLT uses a <xsl:call-template/to build each worksheet. For some reason, when I transform the file, it is inserting...
1
by: madhuxml82 | last post by:
Dear Forum Members, I have generated an XML Schema and a Table of XMLType referencing the XML Schema. Now When I am Inserting the Data into the Table. I am getting the Error 0RA-30937: Error is...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.