473,396 Members | 2,013 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,396 software developers and data experts.

XSLT problem.

The following stylesheet doesn't produce the expected results, (the original
xml document is below).
All I get is:
<html>
<title></title>
<body></body>
</html>
<?xml version="1.0"?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method = "html" encoding="UTF-8" />
<xsl:template match="/">
<html>
<title>
<xsl:apply-templates select = "title" />
</title>
<body>
<xsl:apply-templates select = "item" />
</body>
</html>
</xsl:template>
<xsl:template match="title">
<xsl:value-of select="title" />
</xsl:template>
<xsl:template match="item">
<xsl:apply-templates select = "description" />
</xsl:template>
<xsl:template match="description">
<xsl:value-of select="description" />
</xsl:template>
</xsl:transform>
Source document:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rss version="2.0">
<title>Test</title>

<item>
<description>Hi Guy</description>
<title>November 07, 2003</title>
</item>
</rss>

Nov 12 '05 #1
4 1030
Ayende Rahien wrote:
<xsl:template match="/">
<html>
<title>
<xsl:apply-templates select = "title" /> <xsl:apply-templates select = "/rss/title" />
<xsl:apply-templates select = "item" /> <xsl:apply-templates select = "/rss/item" />
<xsl:template match="title">
<xsl:value-of select="title" />

That's weird. You are trying to output value of title element child of
title element? Most likely it should be

<xsl:template match="title">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="item">
<xsl:apply-templates select="description"/>
</xsl:template>
<xsl:template match="description">
<xsl:value-of select="."/>
</xsl:template>
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog
Nov 12 '05 #2

"Oleg Tkachenko" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:OM**************@TK2MSFTNGP10.phx.gbl...
<xsl:template match="title">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="item">
<xsl:apply-templates select="description"/>
</xsl:template>
<xsl:template match="description">
<xsl:value-of select="."/>
</xsl:template>


This doesn't work either.
Here is the XSLT file:

<?xml version="1.0"?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method = "html" encoding="UTF-8" />
<xsl:template match="/">
<html>
<title>
<xsl:apply-templates select = "title" />
</title>
<body>
<xsl:apply-templates select = "item" />
</body>
</html>
</xsl:template>
<xsl:template match="title">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="item">
<xsl:apply-templates select="description"/>
</xsl:template>
<xsl:template match="description">
<xsl:value-of select="."/>
</xsl:template>
</xsl:transform>
Here is the source XML file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rss version="2.0">
<title>Test</title>

<item>
<description>Hi Guy</description>
<title>November 07, 2003</title>
</item>
</rss>

Here is the result file:
<html>
<title></title>
<body></body>
</html>
Nov 12 '05 #3
Ayende Rahien wrote:
This doesn't work either.


Read my answer once again and note two more fixes:
<xsl:apply-templates select = "/rss/title" />
and
<xsl:apply-templates select = "/rss/item" />

Here is full stylesheet, which works:
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="/">
<html>
<title>
<xsl:apply-templates select="/rss/title"/>
</title>
<body>
<xsl:apply-templates select="/rss/item"/>
</body>
</html>
</xsl:template>
<xsl:template match="title">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="item">
<xsl:apply-templates select="description"/>
</xsl:template>
<xsl:template match="description">
<xsl:value-of select="."/>
</xsl:template>
</xsl:transform>
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog
Nov 12 '05 #4
"Oleg Tkachenko" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:Op**************@TK2MSFTNGP12.phx.gbl...
Ayende Rahien wrote:
This doesn't work either.


Read my answer once again and note two more fixes:
<xsl:apply-templates select = "/rss/title" />
and
<xsl:apply-templates select = "/rss/item" />


Opps!
Thanks.
Thanks for answering my other question (wrong encoding) too.
Nov 12 '05 #5

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

Similar topics

1
by: Ola Natvig | last post by:
Hi all I'm working with a long running, threaded server which serves HTTP requests with content which are passed through a XSLT processor. The XSLT processor I'm using is the Pyana processor. ...
6
by: Pete | last post by:
I am just getting to grips with XML and I was wondering if you could help me with something that no-one seems able or willing to help with.. I have an XSLT file which should be transforming a...
6
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for...
0
by: Mike | last post by:
I'm generating an XSLT document programatically in VB.Net. I'm then trying to apply that XSLT against a cXML document to generate my own internally developed XML document. I'm using RichTextBox...
4
by: Moogy | last post by:
I'm pulling my hair out here. First, I'm new to XML, so that doesn't help, but none of this makes any sense to me. All I'm trying to do is take a simple source XML file and translate it with an...
2
by: chris | last post by:
Hi there, I create an XML file from a dataset like this: System.IO.StreamWriter xmlSW = new System.IO.StreamWriter(FILENAME); dsUserData1.WriteXml(xmlSW, XmlWriteMode.WriteSchema);...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
3
by: thomas.porschberg | last post by:
Hi, I want to read records from a database and export it in an arbitrary format. My idea was to feed a class with a String array fetched from the database and let this class fire SAX events as...
3
by: RC | last post by:
Let's say: if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { // Now I got an XML object here var xmlDocument = XMLHttpRequestObject.responseXML; // next I have...
0
by: ManWithNoName | last post by:
The following question is related to this thread: XSLT, document() function, filename, read non-standard/English characters (like µ) I have a XML file with a non-English character in its name...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.