473,395 Members | 2,222 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,395 software developers and data experts.

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_url" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xsi:schemaLocation="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:stylesheet xmlns:x="some_url" xmlns:placeholder="Placeholder"
version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:namespace-alias stylesheet-prefix="placeholder" 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:stylesheetisn'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 8103
On Aug 6, 2:21 pm, Himself <hims...@davidbrasington.comwrote:
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_url" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xsi:schemaLocation="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:stylesheet xmlns:x="some_url" xmlns:placeholder="Placeholder"
version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:namespace-alias stylesheet-prefix="placeholder" 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:stylesheetisn'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:stylesheet xmlns:x="some_url" xmlns:placeholder="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:namespace-alias stylesheet-prefix="placeholder" result-
prefix="x"/>

<xsl:template match="x:a">
<placeholder:c>
<xsl:attribute name="xsi:schemaLocation">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
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...
0
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)....
4
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,...
3
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...
4
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>...
3
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...
3
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...
9
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>...
5
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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,...

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.