|
Hello,
I created a XSL file to convert a XML file to another XML.
I am running this in Asp.Net but this is not working.
----- ORIGINAL XML -----
<?xml version="1.0" encoding="utf-8" ?>
<siteMap
xmlns="http://schemas.microsoft.com/ASPNet/SiteMap-File-1.0" >
<siteMapNode>
<siteMapNode
url="~/Contacts.aspx"
title="Contacts"
description="Contacts Description"
changefreq="daily"
lastmod="2006-11-01T20:25:42+01:00"
priority="0.4"
google="true" />
<siteMapNode
url="~/Message.aspx"
title="Message"
description="Message Description"
changefreq="daily"
lastmod="2006-11-01T20:25:42+01:00"
priority="0.2"
google="false" />
</siteMapNode>
</siteMap>
----- What XML result should be (Domain Parameter =
"http://www.domain.com") -----
<?xml version="1.0" encoding="UTF-8"?>
< urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
< url>
< loc>http://www.mydomain.com/Contacts.aspx</loc>
< changefreq>daily</changefreq>
< lastmod>2006-11-01T20:25:42+01:00</lastmod>
< priority>0.4</priority>
</url>
</urlset>
----- XSL -----
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.google.com/schemas/sitemap/0.84"
xmlns:dk="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
<xsl:param name="Domain"/>
<xsl:template match="dk:*"/>
<xsl:template match="@*|text()|comment()"/>
<xsl:template match="/">
<xsl:element name="urlset">
<xsl:apply-templates select="//dk:siteMapNode[@google='true']"/>
</xsl:element>
</xsl:template>
<xsl:template match="dk:siteMapNode">
<xsl:element name="url">
<xsl:element name="loc">
<xsl:value-of select="$Domain" />
<xsl:value-of select="substring(@url, 3)"/>
</xsl:element>
<xsl:element name="lastmod">
<xsl:value-of select="@lastmod"/>
</xsl:element>
<xsl:element name="changefreq">
<xsl:value-of select="@changefreq"/>
</xsl:element>
<xsl:element name="priority">
<xsl:value-of select="@priority"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Could someone, please, tell me why is this not working?
And is there a software or web site where I can test a XSL conversion?
Thanks,
Miguel
|
|
|
|
|
Your schemas did not match:
Original XML: xmlns="http://schemas.microsoft.com/ASPNet/SiteMap-File-1.0"
XSLT: xmlns:dk="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0"
Notice ASPNet <> AspNet!
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.google.com/schemas/sitemap/0.84"
xmlns:dk="http://schemas.microsoft.com/ASPNet/SiteMap-File-1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:param name="Domain" select="'http://www.mydomain.com/'"/>
<xsl:template match="/dk:siteMap">
<xsl:element name="urlset">
<xsl:apply-templates select="dk:siteMapNode/dk:siteMapNode[@google='true']"/>
</xsl:element>
</xsl:template>
<xsl:template match="dk:siteMapNode">
<xsl:element name="url">
<xsl:element name="loc">
<xsl:value-of select="$Domain" />
<xsl:value-of select="substring(@url, 3)"/>
</xsl:element>
<xsl:element name="lastmod">
<xsl:value-of select="@lastmod"/>
</xsl:element>
<xsl:element name="changefreq">
<xsl:value-of select="@changefreq"/>
</xsl:element>
<xsl:element name="priority">
<xsl:value-of select="@priority"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
|
|
|
|
|
ok, so correct me if wrong, but a properly formatted XML file does not care about the order of its elements, correct?
<element1-name>John</element1-name><br />
<element2-country>US</element2-country>
would be parsed the same if it were listed as
<element2-country>US</element2-country><br />
<element1-name>John</element1-name>
This 2nd question regarding schema. If I had a .XSD schema file that I wanted to reference, is the following "header" in my .XML file correct?
<br />
<?xml version="1.0" encoding="UTF-8" ?><br />
<br />
< PointOfContact xmlns:xsd="http://www.w3.org/2001/XMLSchema" <br />
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<br />
xsi:noNamespaceSchemaLocation="PointOfContact.xsd"><br />
How do I make the location "relative" (with the dot dots..)?
Thanks!
|
|
|
|
|
http://www.w3schools.com/
They've got alot of XML tutorials. Go through them
ASBESTOS-Greetings
LiquidE
|
|
|
|
|
Hi i have the following code in my xml...
<LogoPath>C:\Reports\GR_Logo.jpg</LogoPath>
How do i call this in the <img src=????/>
Thank you in advance.
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
You can take value of LogoPath tag in a xsl:variable and then assign that varible to src attribute of img tag like
|
|
|
|
|
Thanks, that worked like a charm. but i didn't use it exactly like you did. I only said... <img src="{LogoPath}"/>
This used the tag caled LogoPath.
Would you by any chance know how to embed this image into the html? Say i send this html that gets generated to someone else, and that person doesn't have the image in the path specified...
Thank you for your time.
Nico
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
You can use XSLT to create HTML page of your XML data
and image should be there..means path you have specified...same like in HTML we have imgae in the source location... hope i have replied answer of your question correctly
|
|
|
|
|
Yes thank you, i understand what you mean. I can display the picture, but if i want to send the html (that was generated by the xml and xsl) i need to send the image along with it otherwise it won't display. How do i embed an image so that the image is part of the html in the end?
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
I have a XSchema document and an instance document. Validation of the instance document against the Schema works fine.
My problem is that I'm unable to select nodes from the xml-document. Namespace delarations are shown below.
For instance
XmlNodeList nodeList = xmlDoc.DocumentElement.Select("//Command")
returns 0 nodes.
Xml header:
<?xml version="1.0" ?>
<Commands xmlns="http://nn.taurus.dk/NN"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://nn.taurus.dk/NN">
... rest of xml-document
Schema header:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://nn.taurus.dk/NN"
targetNamespace="http://nn.taurus.dk/NN"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
... rest of XSchema-document
Can anybody tell me what is wrong with either namespace declarations or my select-statement ?
If I remove most of the namespace stuff and only that, the statement
XmlNodeList nodeList = xmlDoc.DocumentElement.Select("//Command")
returns the expected result.
Headers from the files where the Select statement works, are shown below.
Xml header
<?xml version="1.0" ?>
<Commands xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Customer.xsd">
Schema header:
<?xml version="1.0" encoding="utf-8"?>
< xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
|
|
|
I think the problem is that the Command elements are inside the "http://nn.taurus.dk/NN" namespace (declared as default on the Commands element) but this doesn't reflect in the XPath expression.
Try using an Select overload which takes a XmlNamespaceManager . Pass an instance with registered pair "someprefixname" and "http://nn.taurus.dk/NN" and change the XPAth expression to "//someprefixname:Commands".
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
hi,
I am new in ASP.NET , i heard about "diffgram" i have very small information about diffgram(used to get data from the DataSet).
Is anybody tell me some more detail about diffgram and their effective use with small example(if possible).
Thanks,
honey.
|
|
|
|
|
A DiffGram is an XML format that is used to identify current and original versions of data elements. The DataSet uses the DiffGram format to load and persist its contents, and to serialize its contents for transport across a network connection. When a DataSet is written as a DiffGram, it populates the DiffGram with all the necessary information to accurately recreate the contents, though not the schema, of the DataSet, including column values from both the Original and Current row versions, row error information, and row order.
Reference Link: http://www.techinterviews.com/?p=78[^]
|
|
|
|
|
Hi all,
what is the code snippet for getting the image path on the xml to be able to display it on the html but it needs to be embedded into the html file.
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
Hi i have xml file stored in the database and I want to deserialize the xml file from database and want to retrieve the all nodes and child nodes of the xml file stored in database. can anybody help me please
Be +ive
|
|
|
|
|
In case the XML file is stored as plain text in the database, you could just query it and create a DOM representation using XmlDocument.LoadXml method.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
|
Please tell me about following?
What is difference between Declaration Element or Processing Instruction.
Is Declaration Element is necessary for XML file. It should be first element.
Which one is root element in an XML file.
How many times a Processing Instruction can be in an XML file.
What is meant by "Content" in an XML file.
Thanks.
|
|
|
|
|
|
Hi,
i have one XML file, now i need to insert one perticular node in that through .cs page.
How can we achieve this using DOM
Regards
Dayakar D.N
|
|
|
|
|
dayakar_dn wrote: How can we achieve this using DOM
Use the DOM. Take a look around for examples and tutorials. This site (CodeProject) has Articles. There are many others as well for example on msdn.microsoft.com Google is a helpful search tool for finding articles and examples on just about any aspect of software development.
led mike
|
|
|
|
|
Here is your answer in some example code in C++/CLI with an important message for you in the inserted <body> element.
using namespace System;
using namespace System::Xml;
int main(array<System::String ^> ^args)
{
String ^xml =
L"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
L"<note>"
L"<to>dayakar_dn</to>"
L"<from>George L. Jackson</from>"
L"<heading>Reminder</heading>"
L"</note>";
XmlDocument ^doc = gcnew XmlDocument;
doc->LoadXml(xml);
XmlText ^text = doc->CreateTextNode(
L"Please, search with Google first to find your answers.");
XmlElement ^element = doc->CreateElement(L"body");
element->AppendChild(text);
doc->DocumentElement->AppendChild(element);
Console::WriteLine(doc->OuterXml);
return 0;
}
|
|
|
|
|
I'm a current MCAD student. Hope someone can help me with a small query. I am working on an application that saves student records to an xml file. Through using an Xml Schema, a dataset, a new student row and the WriteXml method, I can save a new record to an xml file.
However, if I display an existing record to a series of textboxes and want to amend the record, how do I save the amended record back to the xml file. If I find a student row using the Student ID, populate the textboxes with the details, then use WriteXml method again, that saves a new record to the file instead of amending the existing records. I therefore conclude this is the wrong way of doing things so I am asking for some help.
|
|
|
|
|
gowland0379 wrote: then use WriteXml method again, that saves a new record to the file instead of amending the existing records.
gowland0379 wrote: a dataset
So you are using the .Net framework DataSet? If so you are not handling the DataSet properly that results in a "new" row rather than updating the existing row.
Also in the future you should post .NET questions "the" appropriate .NET forums here on CodeProject (C#, VB.NET, .NET Framework, ASP.NET, ADO.NET )
led mike
|
|
|
|
|
Does any of you guys know an existing webservice, that takes an ISIN code and delivers the name of the paper?
"God doesn't play dice" - Albert Einstein
"God not only plays dice, He sometimes throws the dices where they cannot be seen" - Niels Bohr
|
|
|
|