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: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!

0
himself (2)
8/6/2007 6:21:03 PM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
612 Views

Similar Articles

[PageSpeed] 14

On Aug 6, 2:21 pm, Himself <hims...@davidbrasington.com> wrote:
> 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: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: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>


0
himself (2)
8/6/2007 6:31:06 PM
Reply:

Similar Artilces:

XmlResolver and xsl:include
Have been doing a fair amount of reading but at this point no joy. The scenario is - XSL template is stored within db. - Template has a xsl:include statement as <xsl:include href="inc.template.methods.xsl"/> I now I have to pass a resolver when I use the load method so that it understands the xsl include as in: ' object template is custom class to retrieve templates from the db dim template as new objTemplate dim myresolver as xmlresolver dim mytransfrom as xmltransform ' template.xmlDocRunTime returns a xmldocument object mytransform.load(template.xmlDocRunTim...

Declare Quota for sales person
How can i declare Quota in the system. I cant find this option under the setting declare quota? can you be more specific? -gary "Amit" <Amit@discussions.microsoft.com> wrote in message news:95F9DEED-8F22-48D8-BD6E-A26B737CA739@microsoft.com... > How can i declare Quota in the system. > I cant find this option under the setting ...

In Access, How do I hide records, but include them in the total
I'm running a report where I have work orders. They are grouped by appr and comp. I need to create a report that will show all the appr tickets, but give me a total count of appr and comp. I have the report generated the way I want, with total count, but how do i hide just the comp tickets. xeoimom wrote: >I'm running a report where I have work orders. They are grouped by appr and >comp. I need to create a report that will show all the appr tickets, but >give me a total count of appr and comp. I have the report generated the way >I want, with total count, but ...

#includes
I'm looking over my files this evening, and I'm noticing that some of my #includes (of my own header files) are in my .h files, while some are in my ..cpp files. Sometimes I have used incomplete class declarations as well. I have tried to find some good reading to help me understand this whole thing, but haven't so far. Could I get a bit of advice on this? I don't know if this is related, but one of my source files won't give me any of those "smart tips" when the cursor passes over various objects, unless it is something that I have declared in that file itsel...

Including MDA information in transaction edit reports
GP 8.0 I would like to include MDA entry with the AP transaction edit list so the input can be reviewed before releasing a batch for posting. Same thing applies to our invoicing. What is the best way to accomplish this task? I have coded this once for a customer. The only method that can work seamlessly is a Dexterity customisation which uses a trigger to add extra lines into the temporary table used for the report just prior to printing. David Musgrave [MSFT] Senior Development Consultant Escalation Engineer - Great Plains Microsoft Dynamics Support - Asia Pacific Microsoft Dynamics (f...

copy contents including colour
Hi In cells A1:B73 I have a list of contacts which are colour coded. What I want to be able to do is to be able to enter the name of 1 of the contacts in lets say G1 and it will search for that name in A1:B73 and automatically copy its colour code over. Many thanks for any help. Al Hi, I'm assuming that the colour codeing isn't a result of conditional formatting and it's simply a fill colour. To do this you need VB. Alt+F11 to open vb editor. Double click the worksheet that this data are on and paste the code in on the right. Close VB editor and type your name...

Include a button on toolbar to include/exclude original text when.
When replying/forwarding a message you must go to thru several screens to change your base setting or highlight and delete the message. Add an optional button that would allow you to include/exclude as each message is opened for reply/forwarding. ...

Including Images in Excel Report Builder
We have a client that is attaching jpgs to the item maintenance window in GP and they want an Excel Report Builder report of each inventory item along with its image. It seems that the file name is stored in hex format. Is it possible to include a reference to the image location in an Excel Report Builder report, so the report can include the image inside of Excel? Thanks ...

#include
Is there a way I can view a text version of my files AFTER the #includes have been processed? I tried using the different switches I found in the documentation for use with cl.exe, but I seem to get everything except what I'm looking for. Example Follows this is what I have before:********************************** //NoClass.h (header file class NoClas void DoSomething() //NoClass.cpp (implementation file #include "NoClass.h CWinSomething *pwsSomething this is what I'm trying to see after:************************************ //NoClass.cpp (implementation file //No...

is it included?
I can't access spanish as a language (spell check incl) from office xp. Is there a download somewhere that will complete the ability to change between languages Engl and Span. Thanks Hi Tony! Take a look at: http://www.acoustics-noise.com/ Eric Desart has a downloadable Analysis ToolPak Translator and the site contains essential information on translation issues. Here's some general blurb about it: "It's probably the only utility on the net capable of automatically extracting the translation of Analysis ToolPak functions, with the added functionality that it automatical...

how to include error correction codes?
hi all, what APIs can i use to include/enable error correction codes in VC++ for modem communication. pls suggest methods thru VC++ codes & not AT commands. can anythihg be done using MODEMSETTINGS ? thanx in advance, ...

Bank Check included in Named Printers
The Miscellaneous Check that is currently available for use in Microsofty Dynamics GP version 9.0 should have a corresponding setting for Named Printers, but it does not. Currently we need to go change the GP printer setting right before printing the check, and then change it back right after the check has printed. This needs to be added to the Named Printer Setup. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not s...

xslt formatting question
I would like to make a table using xslt and I need to put html anchors in the table. I want to do something like the following, but can't figure out how... Anyone able to help out? <xsl:for-each select="PayDet"> <tr> <td> <xsl:for-each select="Vendor_Invoice_Id"> <xsl:apply-templates /> <a name="<xsl:value-of select="Vendor_Invoice_Id" />"> <xsl:value-of select="Vendor_Invoice_Id" /> </a> ...

Include problem #2
Hi, This isn't really an MFC specific problem, but it is an MFC application, and this thing is driving me mad! This is an old application in C++ that I have inherited, and I am trying to move it from VS6 to VS2005. One of the headers had a #include <fstream.h> This of course gives me a file not found error, so I changed it to #include <fstream> Now I get hundreds of errors saying: error C2061: syntax error : identifier 'filebuf' I can trace this back to its definition in iosfwd, where it maps back to basic_filebuf (using a typedef) which is itself defined in fst...

Payroll benefits not included in a pay run when garnishment includ
There's a bug in GP 10 that's discussed in KB article # 948265 that describes how benefits aren't included in a payroll check build if garnishments are included. The article gives a workaround but now the deduction isn't a garnishment. Does anyone know if there's a fix in the works for this? ...

Applying SBS2003 R2 schema extension to Active Directory
I need to update my Active Directory on my SBS 2003 R2 server to with the 2003 R2 Active Directory schema to fulfill a prereq on a DFS setup I'm attempting with two 2008 Servers. I'm following this article for the procedure: http://technet.microsoft.com/en-us/library/cc773360%28WS.10%29.aspx I have verified my current schema version object version value is 30, so I know I need to update with R2 schema. The problem is that I only have the DVD installation disc for SBS 2003 R2, and I am not sure if the adprep version on the disc is the correct one. There are two in...

How do I declare a function whose output is an array?
My current workaround to this problem is to declare the function as Public Function xyz(abc as Range) as Variant 'Code 'klm is an array xyz = klm End Function This works efficiently enough, but I would like to tidy up my code by eliminating all non-explicit declarations. Furthermore, can someone tell me what exactly the difference between an array and a range is? For example, if I declare the function as Public Function(abc() as Double) as Variant, how will that make a difference? Is there any advantage of one over the other? Will functions like Rows.Count or Application.Count ...

get-childitem with include
Hi, I'm running into something I don't understand. I want alle files with certain filespec in a certain directory. get-childitem <path> returns all files get-childitems <path>\<filespec> returns all specified files get-childitems <path> -include <filespec> does NOT return the specifies files get-childitems <path> -include <filespec> -recurse does return the specifies files (but also any files in a subdirectory) What is the diference between get-childitems <path>\<filespec> and get-childitems <path> -include &l...

The 'http://www.w3.org/XML/1998/namespace:lang' attribute is not declared Error
I get the following error when I try to validate XML against a schema: The 'http://www.w3.org/XML/1998/namespace:lang' attribute is not declared My questions are: 1. Why I am I getting this error? 2. How can I resolve? I got the schema definition from a third party (ACORD). I tried to do this using two different methods: Method 1 =96 Using a LINQ XDoc (preferred way) Private Function ValidXsd(ByVal AcordXml As String) As Boolean Dim schemas As New XmlSchemaSet() Dim returnVal As Boolean schemas.Add(Nothing, XmlReader.Create(Server.MapPath("Includes \acord-pcs-v1...

Charts: How can I get a date axis to include hours and minutes
Hi I am creating a chart monitoring (my dog's) breathing rate over time. I cannot check the rate at the same time each day so data entries are at different times of day. I have the date column in my spreadsheet in the format dd/mm/yyyy hh:mm When I go to make a simple line chart, if the horizontal axis is in date format, it only resolve the day part of the information, and so all my data for each day appears in the one horizontal place. I can set the axis as text type, and I can then see each data point ok - but it does not reflect the time element of my data. Please can you advi...

Office Address Book included in ?
When I install MS Office, I sometimes do and sometimes don't install all of the Office apps. For Office 2008, I installed just the two apps I use: Word and Excel. In order to use Office's Address Book in Word, I gather I need to install other apps. Is that correct? If so, any need to Uninstall first or can I just install the one or more additional Office 2008 apps? Thanks for the help. -- Norm The Office Address Book I made up from the Contacts maintained in the Entourage database. Entourage must be installed but there's no real need for PPT if you don...

issue with XML and Schema namespace
Hi I am having a hard time with validation of my XML file with given schema. Here are the files: roboerrorlog.xsd <robomss:schema xmlns:robomss="http://www.w3.org/2001/XMLSchema" xmlns="robomss" elementFormDefault="qualified" targetNamespace="robomss"> <robomss:element name="roboErrorLog" type="errorLogType"/> <robomss:complexType name="errorLogType"> <robomss:sequence maxOccurs="unbounded"> <robomss:element name="error" type="errorType"/&...

sharepoint product version vs Sharepoint schema version?
I've new to Sharepoint, and I've been googling sharepoint product versions and schema versions, and I am confused... http://blogs.msdn.com/shaden/archive/2008/01/10/migrated-to-sp1-checking-your-database-schema-version.aspx based on the above page, it sounds like the sharepoint product version should be the same as the schema version, but even within that page the versions are not all the same: I see "12.0.0.4518", 12.0.4518.1016..., where even the 3rd positions are not the same. Then when I google other sites, they refer to version 3.0 of the schema and vers...

DashBoard Summary to contol output
Hi All, I have a spreadsheet with the following columns of data Manufacturer, Product, size, Version, Memory capacity on sheet 1 I want to be able to set a header page where i would have 5 cells each labelled as per above. On each cell would be a kind of cell validation list i guess, where the user could select from a list the manufactuerer, then in the next cell, only have what products that manufacter makes, the next cell, the versions of that product and so on. Once on the cells have been selected with the data needed, i would like it to have either re-summarised the main t...

Generating a report that includes only the current form data
I need to generate a report from a form using a control button that only uses the data currently displayed on the form. I have the basics of form building down, but I keep getting every record in my data table. Thanks. Ed3 Ed3 wrote: > I need to generate a report from a form using a control button that > only uses the data currently displayed on the form. I have the > basics of form building down, but I keep getting every record in my > data table. Thanks. > > Ed3 The fourth argument of the OpenReport method is for an optional WHERE clause (without the word "wh...