473,385 Members | 1,329 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,385 software developers and data experts.

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><Dog TimeStamp="16.02.2004 10:04:48" ModifiedBy="Smith, Geoff"><NameOfDog>Fido</NameOfDog><Weight>10</Weight></Dog><Dog TimeStamp="16.02.2004 10:05:24" ModifiedBy="Scott, Al"><Color>Black</Color><Weight>12</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="NameOfElement" />, ..
Thank you a great lot!!

Daniel Walzenbach
Nov 12 '05 #1
2 1950
"Daniel Walzenbach" <da**********************@freudenberg.de> wrote in message
news:5C**********************************@microsof t.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.02.2004 10:04:48" ModifiedBy="Smith,
Geoff"><NameOfDog>Fido</NameOfDog><Weight>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:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />

<xsl:template match="LogFile/Dog">
<xsl:text>Modified by: </xsl:text>
<xsl:value-of select="@ModifiedBy" />
<xsl:text> (</xsl:text>
<xsl:value-of select="@TimeStamp" />
<xsl:text>)&#x0d;&#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
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...
8
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...
3
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)...
4
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...
3
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...
1
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...
3
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...
4
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...
1
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...
12
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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...

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.