473,385 Members | 1,569 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.

XML to text output

Jim
Hi

I'm fumbling through xml and I'm having a problem which I'm sure is easy
to correct. Here's the xml:

<area1>
<name>John</name>
<age>22</age>
</area1>
<area2>
<city>London</city>
<state>OH</state>
</area2>

I want to pull out name/age/city/state. Seems simple, but because I
have another element (is that the correct term?) area2, things get all
munged up. Like I said, this is very simple. Here's my xsl:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text"/>

<xsl:template match="area1">
<xsl:value-of select="name"/>
<xsl:value-of select="age"/>
</xsl:template>

<xsl:template match="area2">
<xsl:value-of select="city"/>
<xsl:value-of select="state"/>
</xsl:template>

When I try and apply this I get an error:

% xsltproc test.xml test.xsl
test.xml:6: parser error : Extra content at the end of the document
<area2>
^
cannot parse test.xml

What am I doing wrong?

Thanks!

Jul 20 '05 #1
8 5866


Jim wrote:

I'm fumbling through xml and I'm having a problem which I'm sure is easy
to correct. Here's the xml:

<area1>
<name>John</name>
<age>22</age>
</area1>
<area2>
<city>London</city>
<state>OH</state>
</area2>
the above is not well-formed as it doesn't have a single root element
that contains all other elements.

When I try and apply this I get an error:

% xsltproc test.xml test.xsl
test.xml:6: parser error : Extra content at the end of the document
<area2>
^
cannot parse test.xml

What am I doing wrong?


You need to correct your XML to have a root element.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
Jim
Martin Honnen wrote:


Jim wrote:

I'm fumbling through xml and I'm having a problem which I'm sure is
easy to correct. Here's the xml:

<area1>
<name>John</name>
<age>22</age>
</area1>
<area2>
<city>London</city>
<state>OH</state>
</area2>

the above is not well-formed as it doesn't have a single root element
that contains all other elements.

When I try and apply this I get an error:

% xsltproc test.xml test.xsl
test.xml:6: parser error : Extra content at the end of the document
<area2>
^
cannot parse test.xml

What am I doing wrong?

You need to correct your XML to have a root element.


So you can't have multiple root elements in the same XML? Crap--I can't
change the XML--it's what I've been given to work with.

Jul 20 '05 #3
On Mon, 17 May 2004 11:44:16 -0400, Jim <no@no.no> wrote:
Hi

I'm fumbling through xml and I'm having a problem which I'm sure is easy
to correct. Here's the xml:

<area1>
<name>John</name>
<age>22</age>
</area1>
<area2>
<city>London</city>
<state>OH</state>
</area2>
Your XML File must have only one root :
<areas>
<area1>
<name>John</name>
<age>22</age>
</area1>
<area2>
<city>London</city>
<state>OH</state>
</area2>
</areas>

I want to pull out name/age/city/state. Seems simple, but because I
have another element (is that the correct term?) area2, things get all
munged up. Like I said, this is very simple. Here's my xsl:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text"/>

<xsl:template match="area1">
<xsl:value-of select="name"/>
<xsl:value-of select="age"/>
</xsl:template>

<xsl:template match="area2">
<xsl:value-of select="city"/>
<xsl:value-of select="state"/>
</xsl:template>

When I try and apply this I get an error:

% xsltproc test.xml test.xsl
test.xml:6: parser error : Extra content at the end of the document
<area2>
^
cannot parse test.xml

What am I doing wrong?

Thanks!


--
Philippe

Jul 20 '05 #4


Jim wrote:

You need to correct your XML to have a root element.


So you can't have multiple root elements in the same XML? Crap--I can't
change the XML--it's what I've been given to work with.


Check the XML specification
http://www.w3.org/TR/REC-xml/#sec-documents
it says
A data object is an XML document if it is well-formed, as defined in
this specification.
and the production rule for document is
document ::= prolog element Misc*
so in an XML document there is exactly one root element.

What you have been given is formally no XML.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #5
Jim
Martin Honnen wrote:


Jim wrote:

I'm fumbling through xml and I'm having a problem which I'm sure is
easy to correct. Here's the xml:

<area1>
<name>John</name>
<age>22</age>
</area1>
<area2>
<city>London</city>
<state>OH</state>
</area2>

the above is not well-formed as it doesn't have a single root element
that contains all other elements.

When I try and apply this I get an error:

% xsltproc test.xml test.xsl
test.xml:6: parser error : Extra content at the end of the document
<area2>
^
cannot parse test.xml

What am I doing wrong?

You need to correct your XML to have a root element.


Ok, what if I wrapped the whole thing:

<file>
<area1>
<name>John</name>
<age>22</age>
</area1>
<area2>
<city>London</city>
<state>OH</state>
</area2>
</file>
Jul 20 '05 #6
Jim
Jim wrote:
Martin Honnen wrote:


Jim wrote:

I'm fumbling through xml and I'm having a problem which I'm sure is
easy to correct. Here's the xml:

<area1>
<name>John</name>
<age>22</age>
</area1>
<area2>
<city>London</city>
<state>OH</state>
</area2>


the above is not well-formed as it doesn't have a single root element
that contains all other elements.

When I try and apply this I get an error:

% xsltproc test.xml test.xsl
test.xml:6: parser error : Extra content at the end of the document
<area2>
^
cannot parse test.xml

What am I doing wrong?


You need to correct your XML to have a root element.


Ok, what if I wrapped the whole thing:

<file>
<area1>
<name>John</name>
<age>22</age>
</area1>
<area2>
<city>London</city>
<state>OH</state>
</area2>
</file>


I figured it out. I can wrap the whole code in tags and then apply my
sheet.

How can I ignore elements? Say I have the xml:

<file>
<area1>
<name>John</name>
<age>22</age>
</area1>
<area2>
<city>London</city>
<state>OH</state>
</area2>
</file>

and I only want to output some of the elements. Maybe all of area1, but
none of area2. Or all of area1, but just area2/city.

Thanks for all the assistance.

Jul 20 '05 #7
Hello, Jim!
You wrote on Mon, 17 May 2004 14:01:54 -0400:
[Sorry, skipped]

J> How can I ignore elements? Say I have the xml:

J> <file>
J> <area1>
J> <name>John</name>
J> <age>22</age>
J> </area1>
J> <area2>
J> <city>London</city>
J> <state>OH</state>
J> </area2>
J> </file>

J> and I only want to output some of the elements.

<xsl:copy-of/>

J> Maybe all of area1, but none of area2.

[xslt]
<xsl:template match="area1">
<xsl:copy-of select="."/>
</xsl:template match>

<xsl:template match="area2"/>
[/xslt]

J> Or all of area1, but just area2/city.

[xslt]
<xsl:template match="area1">
<xsl:copy-of select="."/>
</xsl:template match>

<xsl:template match="area2">
<xsl:copy-of select="city"/>
</xsl:template match>
[/xslt]

With best regards, Alex Shirshov.
Jul 20 '05 #8
Jim
Alex Shirshov wrote:
Hello, Jim!
You wrote on Mon, 17 May 2004 14:01:54 -0400:
[Sorry, skipped]

J> How can I ignore elements? Say I have the xml:

J> <file>
J> <area1>
J> <name>John</name>
J> <age>22</age>
J> </area1>
J> <area2>
J> <city>London</city>
J> <state>OH</state>
J> </area2>
J> </file>

J> and I only want to output some of the elements.

<xsl:copy-of/>

J> Maybe all of area1, but none of area2.

[xslt]
<xsl:template match="area1">
<xsl:copy-of select="."/>
</xsl:template match>

<xsl:template match="area2"/>
[/xslt]

J> Or all of area1, but just area2/city.

[xslt]
<xsl:template match="area1">
<xsl:copy-of select="."/>
</xsl:template match>

<xsl:template match="area2">
<xsl:copy-of select="city"/>
</xsl:template match>
[/xslt]

With best regards, Alex Shirshov.


Thanks Alex. Just what I needed.

Jim

Jul 20 '05 #9

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

Similar topics

2
by: Jürgen Holly | last post by:
Hi! I have the following xml-node: <docu> <p>Sample: <b>bold</b></p> <p>and text in <i>italic</i></p> </docu> I need to create a text-file, so I set the output-mode to text.
3
by: pradeep gummi | last post by:
I have an XML FILE that is to be converted to Plain Text using an XSL file. Since I just want plain text, I do not want to set any root element during transformation.And if I do not any root...
3
by: Tron Thomas | last post by:
What does binary mode for an ofstream object do anyway? Despite which mode the stream uses, operator << writes numeric value as their ASCII representation. I read on the Internet that it is...
2
by: Buddy Ackerman | last post by:
Apparently .NET strips these white space characters (MSXML doesn't) regardless of what the output method is set to. I'm using <xsl:text> </xsl:text> to output a tab character and...
6
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
3
by: juicy | last post by:
I have create 4 check box, every check on the check box will append text in textarea and any uncheck on check box will remove text in text area. Please give some guide on how to control this.
5
by: grinder | last post by:
first off, i am an extreme newbie to C. i am an undergrad research assistant and i have been shifted to a project that involves building a fairly involved c program. The part that i am stuck on now...
10
by: Michael B. Trausch | last post by:
Alright... I am attempting to find a way to parse ANSI text from a telnet application. However, I am experiencing a bit of trouble. What I want to do is have all ANSI sequences _removed_ from...
1
by: Osoccer | last post by:
...to a different folder and in the relocated file concatenates all of the lines in one long string with a space between each line element. Here is a fuller statement of the problem: I need a...
14
by: Michael | last post by:
Since the include function is called from within a PHP script, why does the included file have to identify itself as a PHP again by enclosing its code in <?php... <?> One would assume that the...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.