XSLT, XML to XML

Hello,

I would like to transform this;

<?xml version="1.0" encoding="utf-8" ?>
<ProductList>
    <Product>
        <ID>1</ID>
        <Name>Gadget</Name>
    </Product>
</ProductList>

to this;

<?xml version="1.0" encoding="utf-8" ?>
<ProductList>
    <Product>
        <ID>1</ID>
        <Name>Gadget</Name>
    </Product>
</ProductList>

Basically I am hoping to use XslTransform and an XSLT stylesheet to change 
the format of some input XML so it can be read directly into a dataset.

Any advice would be appreciated.

Cheers,

Jason 


0
jasongt (6)
10/19/2005 9:08:53 AM
dotnet.xml 7266 articles. 0 followers. Follow

5 Replies
961 Views

Similar Articles

[PageSpeed] 30

Jason wrote:

> I would like to transform this;
> 
> <?xml version="1.0" encoding="utf-8" ?>
> <ProductList>
>     <Product>
>         <ID>1</ID>
>         <Name>Gadget</Name>
>     </Product>
> </ProductList>
> 
> to this;
> 
> <?xml version="1.0" encoding="utf-8" ?>
> <ProductList>
>     <Product>
>         <ID>1</ID>
>         <Name>Gadget</Name>
>     </Product>
> </ProductList>

I hardly see any difference between the two...

-- 
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
0
some2113 (163)
10/19/2005 9:37:16 AM
I'm sorry, I cut and paste the example incorrectly. I would like to 
transform this;

<?xml version="1.0" encoding="utf-8" ?>
<ProductList>
    <Product>
        <ID>1</ID>
        <Name>Gadget</Name>
    </Product>
</ProductList>

To this;

<?xml version="1.0" standalone="yes"?>
<ProductDataSet xmlns="http://tempuri.org/ProductDataSet.xsd">
    <Product>
        <ID>1</ID>
        <Name>Gadget</Name>
    </Product>
</ProductDataSet> 


0
jasongt (6)
10/19/2005 11:30:54 AM
U need only one template in your stylesheet for this:

<xsl:template match="/ProductList">
    <ProductDataSet xmlns="http://tempuri.org/ProductDataSet.xsd">
        <xsl:copy-of select="." />
    </ProductDataSet>
</xsl:template>

Best, Ed.

Jason wrote:

> I'm sorry, I cut and paste the example incorrectly. I would like to
> transform this;
>
> <?xml version="1.0" encoding="utf-8" ?>
> <ProductList>
>     <Product>
>         <ID>1</ID>
>         <Name>Gadget</Name>
>     </Product>
> </ProductList>
>
> To this;
>
> <?xml version="1.0" standalone="yes"?>
> <ProductDataSet xmlns="http://tempuri.org/ProductDataSet.xsd">
>     <Product>
>         <ID>1</ID>
>         <Name>Gadget</Name>
>     </Product>
> </ProductDataSet>

0
10/19/2005 1:17:10 PM
Gomolyako Eduard wrote:
> U need only one template in your stylesheet for this:
> 
> <xsl:template match="/ProductList">
>     <ProductDataSet xmlns="http://tempuri.org/ProductDataSet.xsd">
>         <xsl:copy-of select="." />
>     </ProductDataSet>
> </xsl:template>

No, that's not enough. xsl:copy-of copies element as is and so if in 
source XML an element is in no namespace, it will be in no namespace in 
output, XSLT processor must emit xmlns="" to the Product element then.

Try something like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0">
   <xsl:template match="ProductList">
     <ProductList xmlns="http://tempuri.org/ProductDataSet.xsd">
       <xsl:apply-templates select="@*|node()"/>
     </ProductList>
   </xsl:template>
   <xsl:template match="@*|node()">
     <xsl:copy>
       <xsl:apply-templates select="@*|node()"/>
     </xsl:copy>
   </xsl:template>
   <xsl:template match="*">
     <xsl:element name="{name()}" 
namespace="http://tempuri.org/ProductDataSet.xsd">
       <xsl:apply-templates select="@*|node()"/>
     </xsl:element>
   </xsl:template>
</xsl:stylesheet>

If in your XML there is no attributes, comments or PIs, this can be 
simplified to

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0">
   <xsl:template match="ProductList">
     <ProductList xmlns="http://tempuri.org/ProductDataSet.xsd">
       <xsl:apply-templates/>
     </ProductList>
   </xsl:template>
   <xsl:template match="*">
     <xsl:element name="{name()}" 
namespace="http://tempuri.org/ProductDataSet.xsd">
       <xsl:apply-templates/>
     </xsl:element>
   </xsl:template>
</xsl:stylesheet>



-- 
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
0
some2113 (163)
10/19/2005 1:37:00 PM
Thanks alot for your help guys, much appreciated.

Jason 


0
jasongt (6)
10/20/2005 1:20:09 AM
Reply:

Similar Artilces:

How xslt
Hi all, I have one xml doc like this <test> <orders> <order id='111' typeid='1'> <amount>300</amount> </order> <order id='112' typeid='2'> <amount>300</amount> </order> </orders> <types> <type id='1'> <name>toy</name> </type> <type id='2'> <name>food</name> </type> </types> </test> I want to use xslt to transform it into a new xml -- <test> <orders> <orde...

Linq xml to dictionary help
Hello, I hope someone can help me. I need to load an xml element to a dictionary using the attribute as the key. Here is a sample of the xml. <Colors> .... <FlagColors> <USA> <red order="0"/> <white order="1"/> <blue order="2"/> </USA> </FlagColors> </Colors> I need a sorted list or a dictionary so the colors are in a specific order. For example in the USA the colors need to be ordered red first, white second and blue third. So I need to use the order attribute as the key for the dictio...

Possible to include other tags in a XSLT file?
Is it possible to include addition tags in a XSLT file, that the XSLT processor will, for all practical purposes, ignore? What I'm looking to do is to include a section to contain information regarding what parameters the XSLT file is expecting. Then my program can retrieve the information from the style sheet and prompt the user for the necessary parameters. I'm envisioning the section would be something like this: <myParameters> <Param name="City" prompt="City to search for" /> <Param name="State" prompt...

Excel viewers
Excel can load both "traditional" excel files with the .xls extension, and it can also open "XML" excel files with the .xls extention. Why can't the Excel viewer open both. Currently it can only open excel files; it doesn't recognise XML files. Ultimately, I'd like to produce a markup file which I can then launch with the Viewer. Any suggestions? >>Currently it can only open excel files; it doesn't recognise XML files. The viewer has been around quite a while, well before Excel 2003 which is the first version that can read/write XML file. I ...

XSLT query
Hi I am using XSLT to transfor XML to HTML. I have an XSLT variable , $PAGELINK. I need to specify this value as an href attribute value of <a> tag. something like <a href = $PAGELINK> Click me for new page </a>. This is not working for me. $PAGELINK is treated as a text by XSLT engine. I request your help to do this. Thanks Srinivas. Cnu wrote: > I am using XSLT to transfor XML to HTML. > > I have an XSLT variable , $PAGELINK. I need to specify this value as > an href attribute value of <a> tag. > > something like <a href = $PAGELINK&g...

Reimport XML fails
Followed the instructions here: http://office.microsoft.com/en-us/excel/HA011019641033.aspx#create_map to import an RSS feed for Craig's List: http://newjersey.craigslist.org/zip/index.rss. It works great the first time, but if I want to update it, nothing happens??? Do I have to save the file each time and start with a fresh empty file with just the mapping? LMK - TIA ed ...

XML Validating Reader problem
From: "R. Raghuraman" <raghuraman@infosys.com> Subject: Problem with XMLValidatingReader? Date: 01 April 2004 11:46 Hi, I have a large xml file to process (~ 70 mb). I am trying to use XMLValidating reader. The first step was to try out the example in quickstart samples with minor modifications [significant portions below]. My intention is to validate the file against a DTD before processing and to collect all validation errors in a single pass. Public Class ValidationReadingXMLSample Private WithEvents myXmlValidatingReader As XmlValidatingReader Private myXmlTextR...

XML Application
We use xml files to denote file configurations for our company. We are now getting to the point where need a browser based method of maintaining and creating the configuration files. I had written a small test app for working with XML in ASP.Net and have found that it is painfully slow and cumbersome. Can anyone give me some suggestions or sample links to articles that would help develop an application of this type? I need to allow the user to create a new configuration xml document and modify them with the usual updates, inserts and deletes of nodes. Thanks, Matt ...

xml templates #2
Hi Is there a list available of all the variables that can be used in the xml templates? I would like to add things like cashier name to the receipt and on-hand to Inv received reports. I have tried Cashier.Name etc but no luck. Many thanks Mars ...

system.XML in VB6
I want to do some programming using XML in VB6, specifically MS Access. I have some sample VB.Net code that I can use. It has << Imports System.XML >> at the start of the code. What's the VB6 equivalent of this? I've tried using that, but it just gives an error message. Or maybe I'm putting it in the wrong place. And it doesn't recognise XML operations without it. A dotnet namespace such as System.XML is utterly meaningless in a VB6/VBA environment, and nor is there any equivalent: VB.Net is not simply a more recent version of VB6, it is totally new from...

Format for imported Payable XML file
Hi everyone, I don't have Great Plains, but our company is developing a accouting software that will interact with Great Plains. Specifically, our program will export accounting payable information into XML files which will be recognized and imported by Great Plains. We have a sample XML file for Great Plains, but we can't figure out the meanings of all those fields in the file. Can anyone tell me where I can get information about the format of the XML file or can anyone just explain to me what the meaning of these fields are? Thank you. ...

XML to RTF
Hi all There is an XML file, formed from dataset. I want to see this in the RTF-document like a set of tables. something like: Table1 name +------------------------+------------------------+--------------------+ | Table1.Column1 name | Table1.Column 2 name | Table1.Column3 name| +------------------------+------------------------+--------------------+ |Column1.Row1 data | column2.row1 data | column3.Row1 data | +------------------------+------------------------+--------------------+ |Column1.Row2 data | column2.row2 data | column3.Row2 data | +-------------------...

unknown lookup style
I've modified the Case form to add the "responsiblecontactid" (a predefined field), but when I attempt to add a contact to a case, I get an error: "unknown lookup style - your properties xml is probably not set properly - " Anyone resolve this yet? Jerome Hi Jerome Dont waste your time. I wasted a lot of mine. This is a "documented feature" according to Microsoft terminology. Please refer this techknowledge article for details. http://mbs.microsoft.com/techknowledge/techknowledge.asp?id=29683&target=PS Regards MBab ...

Need help with xml and xsl design
Hi all This is what I have in mind and I will appreciate any suggestions. I am trying to create a xml help system for my application. The schema of the xml file will be <helpsystem> <help id="unique id"> <text>text data</text> <link href="optional tag which will hold a reference to a uri" helpanchor="this is also a optional attribute which will point to a helpid in the same document or a different document" helpanchorhtmlfile=" this attribute will only be present if the helpac...

XSLT Doubt
Is it possible to transform Two XML documents at once using XSLT? -- Regards, Prashant C "Prashant C" <PrashantC@discussions.microsoft.com> wrote in message news:4927C455-11C2-46B5-BC51-B8AD21E2B7C0@microsoft.com... > Is it possible to transform Two XML documents at once using XSLT? Yes. Cheers, Dimitre Novatchev ...

XSLT with Database
Hi All, Is it possible to query database in XSLT? or pass value to XSLT through C# or VB.NET -- Regards, Prashant C Prashant C wrote: > Is it possible to query database in XSLT? or pass value to XSLT through C# > or VB.NET You have three options: 1) global parameters in the stylesheet e.g. <xsl:param name="param-name"/> which you can set with C# or VB.NET code before you run a transformation, see <URL:http://msdn2.microsoft.com/en-us/library/System.Xml.Xsl.XsltArgumentList.AddParam.aspx> 2) extension "script" coded in VB.NET or C# or JScr...

New to XSLT and can't select even the first node... Any Help?
Hey, brand new to XSL and XSLT. I've downloaded an evaluation copy of XML Spy to debug my transformation, but I can't get to frist base. Can anyone help my get straightened out? My XSLT is: <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" /> <xsl:template match="/"> <xsl:for-each select="DataSet_Studio_Appt_Dates/Studio_Appt_Date_Times"> <ItWorked>YEAH</ItWorked> </xsl:for-each> </xsl:t...

XML cannot be opened, try again, opens?
Greetings all, my first post to microsoft.public.excel. I have created about 30 xml spreadsheets. To create the sheets I saved a workbook as XML. I removed the "ss:ExpandedRowCount=". Choppped the XML file into a header & footer & my application supplies from <row> to </row> in the middle. Most of the files load okay but about 1 in ten comes up with a 'Cannot open XML' message from Office Assistant. The thing is, I go back to File Explorer, press enter to load the same file & it loads just fine into Excel. Im running Excel 2003 (11.80.12.6568) SP2 o...

Need Help with reading XML from an URL
I have tried to read XML from an URL using the XmlTextReader: XmlTextReader reader = new XmlTextReader(http://www.<domain>.com/?getxml=1); But reader.ReadOuterXml() only returns an empty string, what's wrong? Any ideas? Apogee Did you move to the root of the document? You might try reader.MoveToContent() and see if that helps. Dan Wahlin Wahlin Consulting Microsoft MVP - ASP.NET and XML Web Services http://www.xmlforasp.net "Apogee" <developer@bitefish.net> wrote in message news:%23JhtLjWQDHA.3192@tk2msftngp13.phx.gbl... > I have tried to read XML from a...

XSLT Development Tools?
Hi group, searching in the Internet I found two products for XML which incorporate a very robust debugger for XSL/XSLT, I would like you to see these products and then, give me your opinion about the development environment or recommend me some other that you know. XML IDE's - http://xslt-process.sourceforge.net - http://www.mentattech.com/themes/mentat/alchemist/index.html Regards, Teksure If you're willing to try Beta software there is also an XSL debugger included in Visual Studio 2005 Professional and above which gives you the ultimate debugging experience which is stepping...

XML Receipt Text Comparisons
I'm having problems comparing two text fields. Why doesn't this work? <SET name="LookupCodeFreight" custom="true" type="vbString"> "Freight" </SET> .... <IF> <CONDIDTION> Entry.Item.ItemLookupCode = LookupCodeFreight </CONDIDTION> <THEN> <ROW> Entry.Item.ItemLookupCode " Is Freight" </ROW> </THEN> <ELSE> <ROW> Entry.Item.ItemLookupCode " Is Not Freight" </ROW> </ELSE> </IF> Results are always false ie. Freight Is Not F...

How do you create an XML document based on an XML Schema?
How do you create an XML document based on an XML Schema? I have an XML Schema that defines several primary XML document types (i.e. the top-level element contains 4 complex type child elements in a choice group). I used xsd.exe to generate classes to simplify setting the values in the instance objects. My question is how do I serialize the objects to an XML document based on a specific child element referenced in the XML schema's choice group? Regards, Thomas ...

XML-to-MSWord
Hi I've got a really laborious task at my work. I have to write documentatio to my C# code in MS Word till Wednesday. They don't care that, documentatio already exist in MSDN format generated by nDoc. They still want it, in M Word Format While I was writing a code, I always documented all my methods, class an namespaces in VS.NET XML format documentation. But now, I've got 130 page long XML document, MS Word template, and 3 days to copy and past all of dat in XML to new MS Word document Do you know any program, which could help me in automation this laboriou process For all of ...

New to xml
I'm trying to write my xsl to display an unordered list fromt the xml file where location is equal to top: <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > <siteMapNode url="~/index.aspx" title="Home" location="top"> <siteMapNode url="~/about_us/index.aspx" title="About Us" location="top" > <siteMapNode url="~/about_us/mediaroom.aspx" title="Media Room" /> <siteMapNode url="~/about_us/awards.aspx" title="Awards" /> <siteMapNo...

XSLT validation
Reposting since this forum might be more appropriate for my question. I have written a simple piece of code in C# that takes a xml file as input, applies a xsl transform and outputs a xml file. I want to validate my output xml file against the xsl file to verify that the output is as expected. How can i do this? Thanks in advance! KL wrote: > I have written a simple piece of code in C# that takes a xml file as input, > applies a xsl transform and outputs a xml file. > > I want to validate my output xml file against the xsl file to verify that > the output is as exp...