473,881 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extracting custom data with an XSLT?


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 XSLT to produce
HTML code.

The problem I have is that no matter what translation it runs through,
it ALWAYS includes data that I don't match in the XSLT!! All I want to
do is extract specific fields from the XML. Here's the XML source.
Simple...

<?xml version="1.0"?>
<rss version="0.92">
<channel>

<docs>http://backend.userlan d.com/rss092</docs>
<title>Comics : Calvin and Hobbes</title>
<description>Co mics: Calvin and
Hobbes</description>

<managingEditor >cr*******@live journal.com</managingEditor>

<link>http://www.ucomics.com/calvinandhobbes/</link>
<lastBuildDate> Sat, 27 Dec 2003 01:00:02
GMT</lastBuildDate>
<item>
<title>Comics : Calvin and Hobbes</title>

<link>http://images.ucomics. com/comics/ch/1992/ch921226.gif</link>
<description>&l t;img

src=&quot;http://images.ucomics. com/comics/ch/1992/ch921226.gif";
border=&quot;0& quot;
alt=&quot;Today &apos;s Calvin and
Hobbes&quot;&gt ;
</description>
</item>
</channel>
</rss>

Now, here's the VB.NET code that I use to apply my XSLT:

Dim xslt As New XslTransform
Dim doc As New XmlDocument
Dim writer As XmlTextWriter = New
XmlTextWriter(" c:\temp\transfo rm.html", Nothing)

doc.Load("c:\te mp\XMLtest.xml" )

Try
xslt.Load("c:\t emp\XMLtest.xsl t")
xslt.Transform( doc, Nothing, writer, Nothing)

Catch ex As Xsl.XsltExcepti on
Console.WriteLi ne("Transform Failed")

Catch ex As Exception
Console.WriteLi ne(ex.Message & " " & ex.StackTrace)

End Try

MsgBox("DONE!")

Now, I have tried SO many variations of an XSLT I don't even not what
to post here. I'm taking from 3 books, and the problem is that the
exported HTML ALWAYS includes the data associated with the items that
I'm not attempting to match!

Here's my latest failure of an XSLT:

<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" encoding="utf-8" />

<xsl:template match="channel" >
<xsl:text>
CORE CHANNEL:
</xsl:text>

<xsl:apply-templates/>
</xsl:template>

<xsl:template match="channel/item">
TITLE <xsl:value-of select="title"/>
</xsl:template>

</xsl:stylesheet>

And here's the result:

CORE CHANNEL: http://backend.userland.com/rss092Comics: Calvin and
HobbesComics: Calvin and
Hobbescr******* @livejournal.co mh...ww.ucomics.com/calvinandhobbes/Sat,
27 Dec 2003 01:00:02 GMT TITLE Comics: Calvin and Hobbes

PLEASE help me get around this pathetic problem. Obviously there's
some unnamed rule, but the 3 books that I have on the subject mention
NOTHING about this because all the examples contain data that's all
used; no throw away data.

So, how do I throw away the data I don't want when transforming with an
XSLT?

Thanks!
Moogy
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message217830.html

Nov 12 '05 #1
4 2177

"Moogy" <Mo*********@ma il.mcse.ms> wrote in message
news:Mo******** *@mail.mcse.ms. ..

So, how do I throw away the data I don't want when transforming with an
XSLT?


Read about "built-in templates" and deafault processing in XSLT.

As a rule, whenever unwanted elements are being processed and their text
node descendents appear in the output, this means that you have an
xsl:apply-templates instruction, which selects for processing some nodes,
for which you haven't provided a matching template. In such a case the XSLT
processor uses its built-in templates. The net result is that all text-node
descendents get copied to the output.

In your case the solution is simple: just match a text node with an empty
rule like this:

<xsl:template match="text()"/>
Hope this helped.

Dimitre Novatchev.
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
Nov 12 '05 #2
Hi,
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.


There is a great article explaining RSS Feeds/XML at
http://www.softwaremarketingresource.com/article18.html
that will likely help you understand a little more.

Best of luck
Rachel Small

Nov 12 '05 #3
Moogy,

Dimitre explained this well, but there is a cheap and dirty fix if it helps.

The default processing starts at the root and goes down each branch in your
XML looking for matching templates (with no mode). When it finds a match,
portions of your document that are closer to the leaf are considered
handled.

Thus you can include a root node that forces a single entry point into your
processing. You can explicilty control all further processing through
xsl:apply-templates and mode values. It's approches heresy, but it's very
effective.

--
Kathleen Dollard
Microsoft MVP
Author "Code Generation in Microsoft .NET"
"Moogy" <Mo*********@ma il.mcse.ms> wrote in message
news:Mo******** *@mail.mcse.ms. ..

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 XSLT to produce
HTML code.

The problem I have is that no matter what translation it runs through,
it ALWAYS includes data that I don't match in the XSLT!! All I want to
do is extract specific fields from the XML. Here's the XML source.
Simple...

<?xml version="1.0"?>
<rss version="0.92">
<channel>

<docs>http://backend.userlan d.com/rss092</docs>
<title>Comics : Calvin and Hobbes</title>
<description>Co mics: Calvin and
Hobbes</description>

<managingEditor >cr*******@live journal.com</managingEditor>

<link>http://www.ucomics.com/calvinandhobbes/</link>
<lastBuildDate> Sat, 27 Dec 2003 01:00:02
GMT</lastBuildDate>
<item>
<title>Comics : Calvin and Hobbes</title>

<link>http://images.ucomics. com/comics/ch/1992/ch921226.gif</link>
<description>&l t;img

src=&quot;http://images.ucomics. com/comics/ch/1992/ch921226.gif";
border=&quot;0& quot;
alt=&quot;Today &apos;s Calvin and
Hobbes&quot;&gt ;
</description>
</item>
</channel>
</rss>

Now, here's the VB.NET code that I use to apply my XSLT:

Dim xslt As New XslTransform
Dim doc As New XmlDocument
Dim writer As XmlTextWriter = New
XmlTextWriter(" c:\temp\transfo rm.html", Nothing)

doc.Load("c:\te mp\XMLtest.xml" )

Try
xslt.Load("c:\t emp\XMLtest.xsl t")
xslt.Transform( doc, Nothing, writer, Nothing)

Catch ex As Xsl.XsltExcepti on
Console.WriteLi ne("Transform Failed")

Catch ex As Exception
Console.WriteLi ne(ex.Message & " " & ex.StackTrace)

End Try

MsgBox("DONE!")

Now, I have tried SO many variations of an XSLT I don't even not what
to post here. I'm taking from 3 books, and the problem is that the
exported HTML ALWAYS includes the data associated with the items that
I'm not attempting to match!

Here's my latest failure of an XSLT:

<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" encoding="utf-8" />

<xsl:template match="channel" >
<xsl:text>
CORE CHANNEL:
</xsl:text>

<xsl:apply-templates/>
</xsl:template>

<xsl:template match="channel/item">
TITLE <xsl:value-of select="title"/>
</xsl:template>

</xsl:stylesheet>

And here's the result:

CORE CHANNEL: http://backend.userland.com/rss092Comics: Calvin and
HobbesComics: Calvin and
Hobbescr******* @livejournal.co mh...ww.ucomics.com/calvinandhobbes/Sat,
27 Dec 2003 01:00:02 GMT TITLE Comics: Calvin and Hobbes

PLEASE help me get around this pathetic problem. Obviously there's
some unnamed rule, but the 3 books that I have on the subject mention
NOTHING about this because all the examples contain data that's all
used; no throw away data.

So, how do I throw away the data I don't want when transforming with an
XSLT?

Thanks!
Moogy
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message217830.html

Nov 12 '05 #4

"Kathleen Dollard" <Ka******@mvps. org> wrote in message
news:Oz******** ******@TK2MSFTN GP10.phx.gbl...
Moogy,
[snip]
Thus you can include a root node that forces a single entry point into your processing. You can explicilty control all further processing through
xsl:apply-templates and mode values. It's approches heresy, but it's very
effective.


Sure, this is a very appropriate advice.

It is not "heresy" :o) -- only there are some rare cases when one has to
write completely generic stylesheets in pure push style, that should work
with any, unknown in advance source xml document -- in any such case
disregarding certain types of nodes can be guaranteed by specifying an empty
template rule.

One can also argue that "push style" is more maintainable than "pull
style" -- I am not a fanatic at all, but it is good to list all pros and
cons when giving a recommendation.
Happy New Year!
Dimitre Novatchev.
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
Nov 12 '05 #5

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

Similar topics

7
1956
by: Luc Tremblay | last post by:
Given the typical following code: void Listener::HandleEvent(const Event& event) { // handling code } In a "clean" fashion, how is it possible to add custom data (to be subsequently accessed) to the Event instance? By custom data i mean practically anything, from a class to a single int. Particularly to my case,
5
2963
by: Michael Hill | last post by:
Hi, folks. I am writing a Javascript program that accepts (x, y) data pairs from a text box and then analyzes that data in various ways. This is my first time using text area boxes; in the past, I have used individual entry fields for each variable. I would now like to use text area boxes to simplify the data entry (this way, data can be produced by another program--FORTRAN, "C", etc.--but analyzed online, so long as it is first...
0
1517
by: suresh | last post by:
hi, how do we define the custom data using solutionXML tag in Visio XML file. I have opened the already existing XML file and defined the data as the code given below. <SolutionXML Name='SolutionXML1'></SolutionXML> Now i have opened the file from an application and tries to save the file with some new data, it gives an exception error. I don't know how to rectify this. expecting your reply....
0
1093
by: Bret Pehrson | last post by:
I'm using a custom data source for my (WinForms) datagrid: public class MyDataSource : IList { // ... } each row is a: public class MyDataRow
5
3707
by: Richard Bysouth | last post by:
Hi I am trying to create an object that I can use to bind to a grid in my Win app. All of the examples that I have found on custom data sources have the properties (e.g. FirstNamer, LastName) of the objects making up the columns in a grid. In my situation however there can be any number of columns. I have created Row and Column classes, each of which have properties such as Visible. Columns have a Caption property which should become...
6
2248
by: Gaz | last post by:
Hi guys. I've been lookig for this in the numpy pdf manual, in this group and on google, but i could not get an answer... Is there a way to create a custom data type (eg: Name: string(30), Age: int(2), married: boolean, etc) and then use that custom data in a matrix? Actually, this is a two question question :P Im doing a simple hex based game and i need a way to store every hex property (color, owner,x, y, etc) in a matrix's "cell",...
2
1382
by: renatois | last post by:
DropDownList with custom Data Display in a GridView Hi all, I have a GridView that has a STATUS template field showing a DropDownList on Edit Mode with the users status that can be C, I, B, E. That´s all working fine, the thing is that I want to configure the Data Field Display of the DropDownList that is showing C ,I ,B ,E to corresponding strings. Any solution? Thank you all
1
1459
by: jehugaleahsa | last post by:
Hello: I am experiencing performance related issues when my custom data structures work with value types. I use generics to prevent boxing wherever I can. For instance, I use IEqualityComparer, etc. I have gone through most of my data structures and verified that I don't compare to null or call methods that would box my value types. However, I am still experiencing performance problems. I can process strings faster than I can process...
0
1181
by: napstar | last post by:
I would also like to know how to create a custom data set in SSRS
0
9930
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9776
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11103
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10819
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9555
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7953
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7113
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4196
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3225
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.