473,561 Members | 3,564 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to transform XML by using XSLT

Hi
I need to know how to transform a XML file by using a XSLT file. Consider the following XML file

<?xml version="1.0" encoding="UTF-8" standalone="yes "?><LogFile><Do g TimeStamp="16.0 2.2004 10:04:48" ModifiedBy="Smi th, Geoff"><NameOfD og>Fido</NameOfDog><Weig ht>10</Weight></Dog><Dog TimeStamp="16.0 2.2004 10:05:24" ModifiedBy="Sco tt, Al"><Color>Blac k</Color><Weight>1 2</Weight></Dog></LogFile

By the magic of some XSLT file I want the following output to be created.

Modified by: Smith, Geoff (16.02.2004 10:04:48
Name of the Dog: Fid
Weight: 1

Modified by: Scott, Al (16.02.2004 10:05:24
Color: Blac
Weight: 1

Does anybody know how this can be done? How can I output ALL elements of one node without having to name all children using <xsl:value-of select="NameOfE lement" />, ..
Thank you a great lot!!

Daniel Walzenbach
Nov 12 '05 #1
2 1962
"Daniel Walzenbach" <da************ **********@freu denberg.de> wrote in message
news:5C******** *************** ***********@mic rosoft.com...
I need to know how to transform a XML file by using a XSLT file. Consider the following XML file:

<?xml version="1.0" encoding="UTF-8" standalone="yes "?><LogFile >
<Dog TimeStamp="16.0 2.2004 10:04:48" ModifiedBy="Smi th,
Geoff"><NameOfD og>Fido</NameOfDog><Weig ht>10</Weight>
</Dog> : : Modified by: Smith, Geoff (16.02.2004 10:04:48)


Daniel,

You'll have to set the xsl:output element to set an output method of text,
and then it's simply a matter of placing the results of several XPath
expressions at the desired places in a document.

For starters,

- - - DogLog.xsl (excerpt)
<xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />

<xsl:template match="LogFile/Dog">
<xsl:text>Modif ied by: </xsl:text>
<xsl:value-of select="@Modifi edBy" />
<xsl:text> (</xsl:text>
<xsl:value-of select="@TimeSt amp" />
<xsl:text>)&#x0 d;&#x0a;</xsl:text>
</xsl:template>

<xsl:template match="/">
<xsl:apply-templates select="LogFile/Dog" />
</xsl:template>

</xsl:stylesheet>
- - -

With text output, settings for whitespace preservation may conflict with
natural and clear indenting of XSL source, so rather than just use a basic
literal text document with preserved whitespace, I use xsl:text elements
above to precisely distinguish the literal text content I want emitted into
the target document from the other whitespace that is only used to
present a readable stylesheet.

In these text elements, you see the two character entities, #x0d; and #x0a;
which correspond to the carriage return and line feed (ie, the character
codes you may be more familiar with from C languages as "\r\n") that intro-
duce a newline into the text output.

There are two template rules in this stylesheet. The first matches the root
node of the document (which in XPath-thinking, is the node containing the
document element, LogFile) and applies the second template (iteratively)
over each record wrapped by the Dog element.

The xsl:value-of elements are how the result of XPath expressions against
the source document get injected into the result document. From this basic
skeleton, you should be able to extend it further to create text reports
formatted however you like.
Derek Harmon
Nov 12 '05 #2
Thank you Derek. I have to look for some kind of tutorial for this kind of stuff.

Best regard

Daniel
Nov 12 '05 #3

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

Similar topics

5
3591
by: KathyB | last post by:
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an instruction document (not data based) - same as using an xml web control. The resulting html is on the client? but what about the server side of...
8
2170
by: Luther Miller | last post by:
I am using the XML tranform functionality in .NET to transform data in a DataSet into XMLSS using an XSLT file I have created. There are about 100 columns and only about 120 rows in the data table being transformed - modest amount of data to say the least. The transform takes at least 10 seconds on a fast machine, which seems absolutely...
3
2458
by: Jason S | last post by:
Hello Group, I am just about tearing my hair out with this one and thought someone may have some insight. I have a transform that wasn't working so I grabbed the nearest debugger (xselerator) and saw that it works just fine. Now what I mean by not working is that it just silently fails to produce the expected output... no exceptions are...
4
4812
by: schneider | last post by:
Anyone know if there is a way to dynamicly create a Xslt template/s and use them as an xml transform with-out use files for the Xslt? All the methods I see use files. I want to create a Xslt transform via code? Any examples would be great.
3
2126
by: Andy | last post by:
Hi all, I'm having a problem doing an Xslt transform in code. I've done it before, so I'm not really sure why its not working. The problem is that the result of the transform is an empty string. I expected the xml to be transformed into a plain text document. Everything works fine when i transform using XmlPad. Here's the code (which...
1
2677
by: Danny Lesnik | last post by:
Hi i have my XML file c:\prd.xm <?xml-stylesheet type="text/xsl" href="prd.xsl"?><products><product><a>2</a><b>3</b></product><product><a>4</a><b>2</b></product></products This is my XSL file <?xml version="1.0" encoding="windows-1255" ?><xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform...
3
302
by: Peter Row | last post by:
Hi, I have 2 XML files and 1 XSLT file. The second XML file has the following declarative 1st line: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> ....the 1st one (the one to be transformed) doesn't. In the transform file I load the 2nd XML file which contains
4
2090
by: WStoreyII | last post by:
I wish to know how to set it up so that when an xml webservice is called that instead of displaying the xml in the browser it will render it with a xslt file the problem is i dont know how to do this? Thanks again WStoreyII
1
2604
by: Steve | last post by:
Using VB.NET 2.0 I have a simple routine that attempts transforms an XmlDocument with an XSLT stylesheet into HTML. Under the old 1.1 framework with XslTransform, everything worked fine. Now using XslCompiledTransform, the Transform method hangs. My code: Function TransformXML(ByRef FacXML As Xml.XmlDocument, ByVal XslFile As String) As...
12
2885
by: das | last post by:
Hello all, I am using .NET XSLT to transform an XML into another XML file. All this is fine with small files, but when tested with big files (30MB) it is taking between 1hr-2hrs to just transform the file. Here is the code snippet: XPathDocument xdoc = new XPathDocument(fs); XPathNavigator nav = xdoc.CreateNavigator();...
0
7859
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. ...
0
8088
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...
1
7618
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5472
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...
0
3617
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3600
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2068
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
1
1181
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
896
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...

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.