473,785 Members | 2,435 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to include schema declaration in xslt output

I apologize if this has been answered before, I couldn't find it.

I'm trying to transform XML to XML and specify a schema in the output
XML. I am transforming nodes to different local names while keeping
the same namespace. This works fine, until I try to introduce the
schema.
My input looks like this:

<a xmlns="some_url ">
<b>doo dah</b>
</a>

I want this output:

<x:c xmlns:x="some_u rl" xmlns:xsi="http ://www.w3.org/2001/XMLSchema-
instance" xsi:schemaLocat ion="some_url myschema.xsd">
<x:d>doo dah</x:d>
</x:c>

Here is a stylesheet that works, but doesn't output the schema
location:

<xsl:styleshe et xmlns:x="some_u rl" xmlns:placehold er="Placeholder "
version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:namespac e-alias stylesheet-prefix="placeho lder" result-
prefix="x"/>
<xsl:template match="x:a">
<placeholder: c>
<xsl:apply-templates select="@* | node()"/>
</placeholder:c>
</xsl:template>
<xsl:template match="x:b">
<placeholder: d>
<xsl:apply-templates select="@* | node()"/>
</placeholder:d>
</xsl:template>
<xsl:template match="@*|node( )">
<xsl:copy>
<xsl:apply-templates select="@*|node ()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

I'm using XmlSpy 5.0 with microsoft MSXML selected to do my tests.
If I add the schema declaration to the xsl file it refuses to
transform because the root node <xsl:stylesheet isn't in the schema.
I can't figure out how to tell it to output the schema declaration,
but not to validate the input or the stylesheet itself using that
schema.

Any help would be greatly appreciated!

Aug 6 '07 #1
1 8126
On Aug 6, 2:21 pm, Himself <hims...@davidb rasington.comwr ote:
I apologize if this has been answered before, I couldn't find it.

I'm trying to transform XML to XML and specify a schema in the output
XML. I am transforming nodes to different local names while keeping
the same namespace. This works fine, until I try to introduce the
schema.
My input looks like this:

<a xmlns="some_url ">
<b>doo dah</b>
</a>

I want this output:

<x:c xmlns:x="some_u rl" xmlns:xsi="http ://www.w3.org/2001/XMLSchema-
instance" xsi:schemaLocat ion="some_url myschema.xsd">
<x:d>doo dah</x:d>
</x:c>

Here is a stylesheet that works, but doesn't output the schema
location:

<xsl:styleshe et xmlns:x="some_u rl" xmlns:placehold er="Placeholder "
version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:namespac e-alias stylesheet-prefix="placeho lder" result-
prefix="x"/>
<xsl:template match="x:a">
<placeholder: c>
<xsl:apply-templates select="@* | node()"/>
</placeholder:c>
</xsl:template>
<xsl:template match="x:b">
<placeholder: d>
<xsl:apply-templates select="@* | node()"/>
</placeholder:d>
</xsl:template>
<xsl:template match="@*|node( )">
<xsl:copy>
<xsl:apply-templates select="@*|node ()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

I'm using XmlSpy 5.0 with microsoft MSXML selected to do my tests.
If I add the schema declaration to the xsl file it refuses to
transform because the root node <xsl:stylesheet isn't in the schema.
I can't figure out how to tell it to output the schema declaration,
but not to validate the input or the stylesheet itself using that
schema.

Any help would be greatly appreciated!
I figured it out:

It works if i declare the schema namespace in the xsl but output the
schema location as an attribute. Here is the modified xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:styleshe et xmlns:x="some_u rl" xmlns:placehold er="Placeholder "
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance" version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:namespac e-alias stylesheet-prefix="placeho lder" result-
prefix="x"/>

<xsl:template match="x:a">
<placeholder: c>
<xsl:attribut e name="xsi:schem aLocation">some _url myschema.xsd</
xsl:attribute>
<xsl:apply-templates select="@* | node()"/>
</placeholder:c>
</xsl:template>

<xsl:template match="x:b">
<placeholder: d>
<xsl:apply-templates select="@* | node()"/>
</placeholder:d>
</xsl:template>

<xsl:template match="@*|node( )">
<xsl:copy>
<xsl:apply-templates select="@*|node ()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
Aug 6 '07 #2

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

Similar topics

3
1920
by: william_hulse | last post by:
The general process i am currently working on is this: STEP 1 xml doc1 is transformed using stylesheet1 to produce xml doc2 - xml doc1 has a namespace declaration as follows... <?xml version="1.0" encoding="iso-8859-1" standalone="yes"?> <?xml-stylesheet type="text/xsl" href="G:\Working\User\Will_Hulse\NEW\xmldb\code\Bank_Statements_Schema\EXBAEUFRED01.xsl"?>
0
2181
by: Adam Retter | last post by:
Hi Guys, I have a need to create a html form based on my schema. I initially decided to do this using xql, have got some way but am finding this difficult (it may be as I am very new to xql). The html form needs to be dynamically generated from the schema as the schema may change in future. We need the forms to provide a UI for users to edit the underlying xml documents represented by the schema. Im wandering if there is an easy way...
4
1602
by: Porthos | last post by:
Hi All, I've been working on mining data from a schema file (all attribute data so far) and have come to the point where I need to get information that is contained in tags. For instance, <tag>My Data Here</tag>. I've tried using the <xsl:value-of select="tag"/> element, but it does not appear to work in schema files. Is this correct? Is there another way to get at this data? -James
3
5921
by: Davide Bedin | last post by:
I have a "library" schema with the simple and complex types I commonly use in other schemas and then several other schemas, maybe created by other developers, that import/include the library schema. And then other schemas can extend it..... The classes created by XSD really help to make the development faster and easier. I really would like to use XSD.exe tool as much as possible and to avoid editing the classes defined by the tool. ...
4
2201
by: Philip Rayne | last post by:
Probably a bit of a newbie question this. I have an XML file like this: <?xml version="1.0" standalone="yes"?> <AuditLogonGroup xmlns="http://tempuri.org/AuditLogon.xsd"> <AuditLogon> <Username></Username> <IPAddress></IPAddress> </AuditLogon> <AuditLogonGroup>
3
4830
by: Gordon Moore | last post by:
Hi, I'm new to using xml/xslt and although I can create an xml document using the dataset.WriteXml statement, and I have created an xslt to transform the xml into the output I want, I have to manually add the xsl reference statement to the xml file. i.e. <?xml version="1.0" standalone="yes"?> <?xml:stylesheet type="text/xsl" href="Questions.xsl"?> --> I have to
3
400
by: askar.bektassov | last post by:
Hello guys, I'm new to XML so sorry for probably 'obvious' question I have the following xml schema <!-- dynamicMeasurement.xsd --> <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:measure="http://www.example.org" targetNamespace="http://www.example.org">
9
3020
by: mstilli | last post by:
Hi, I am trying to use schema for server side validation using xerces to catch the validation errors. validating this XML: <Content4> <textarea13></textarea13> <binaryobject3></binaryobject3>
5
4111
by: pronerd | last post by:
I am trying to run an XSLT on a schema (XSD) file. The schema file has a "xsd:include" tag that includes another XSD file. When I load the schema in XML editors like XML Spy the data from all of the files is loaded. When I run the XSL translation only the XSD data from the first file is loaded and translated. The data from the file referenced in the included tag is skipped. Anyone have any ideas why? Example XSD file <?xml...
0
9480
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
10325
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
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
7499
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
6739
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();...
1
4050
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
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
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.