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

change output order

I don't usually post questions, but 2 days of googleing and frustration
have broken my resistance.

I have some scary looking xml that looks something like this:

<?xml version="1.0"?>
<foo xmlns='urn:xxx:yyy'>
<stuff type="why">
<morestuff type="do">
<evenmore>
<stuff_overload type="this">
<finally name="{last}">
<value>Doe</value>
</finally>
<finally name="{first}">
<value>John</value>
</finally>
<finally name="{number}">
<value>14</value>
</finally>
</stuff_overload>
</evenmore>
</morestuff>
</stuff>
<stuff type="why">
<morestuff type="do">
<evenmore>
<stuff_overload type="this">
<finally name="{last}">
<value>Smith</value>
</finally>
<finally name="{first}">
<value>Jane</value>
</finally>
<finally name="{number}">
<value>15</value>
</finally>
</stuff_overload>
</evenmore>
</morestuff>
</stuff>
</foo>
Which I would like to transform into this:
John,Doe,14
Jane,Smith,15

So I wrote this:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xdm="urn:xxx:yyy">
<xsl:output method="text" indent="yes"/>
<xsl:strip-space elements="xdm:foo xdm:stuff xdm:morestuff xdm:evenmore
xdm:stuff_overload"/>

<xsl:template match="xdm:finally">
<xsl:apply-templates select="xdm:finally[@name='{first}']"/>
<xsl:apply-templates select="xdm:finally[@name='{last}']"/>
<xsl:apply-templates select="xdm:finally[@name='{number}']"/>
</xsl:template>

<xsl:template match="xdm:finally[@name='{first}']"><xsl:value-of
select="xdm:value"/>
</xsl:template>

<xsl:template match="xdm:finally[@name='{last}']">,<xsl:value-of
select="xdm:value"/>
</xsl:template>

<xsl:template match="xdm:finally[@name='{number}']">,<xsl:value-of
select="xdm:value"/><xsl:text>
</xsl:text>
</xsl:template>

</xsl:stylesheet>

But my output looks like:
,DoeJohn,14
,SmithJane,15

I've also tried nesting the templates, and about 100 other things. Any
ideas on what I'm doing wrong would be a great help.

-tia

Jul 20 '05 #1
13 2014
But my output looks like:

Your template
xsl:template match="xdm:finally">

is never called as each of your finally element has a name attribute and
is matched with higher priority by one of your other templates, so the
finally elements are processed in the order they appear in the source.

If it was called it would produce no result as it iis
<xsl:template match="xdm:finally">
<xsl:apply-templates select="xdm:finally[@name='{first}']"/>
<xsl:apply-templates select="xdm:finally[@name='{last}']"/>
<xsl:apply-templates select="xdm:finally[@name='{number}']"/>
</xsl:template>
so it just applies templates to xdm:finally children of the current
xdm:finally element but there are no such children.

You want to match on teh parent of teh finally elements so change the
above to

<xsl:template match="xdm:stuff_overload">
<xsl:apply-templates select="xdm:finally[@name='{first}']"/>
<xsl:apply-templates select="xdm:finally[@name='{last}']"/>
<xsl:apply-templates select="xdm:finally[@name='{number}']"/>
</xsl:template>

David

Jul 20 '05 #2
Wow. Thank you. That did it!

Jul 20 '05 #3
FlickChick wrote:
I don't usually post questions, but 2 days of googleing and frustration
have broken my resistance.
Who told you to use XSLT for such a simple task ?
There are tools which are easier to handle.
The follwing script in XMLgawk works, I tested it.

BEGIN { XMLMODE=1; OFS="," }

XMLCHARDATA {
data = $0
}

XMLSTARTELEM == "finally" {
name = XMLATTR["name"]
}

XMLENDELEM == "value" {
if (name == "{last}")
last = data
if (name == "{first}")
first = data
if (name == "{number}")
number = data
}

XMLENDELEM == "stuff_overload" {
print first, last, number
}
I've also tried nesting the templates, and about 100 other things. Any
ideas on what I'm doing wrong would be a great help.


If you need XSL output, XSLT might be the right tool.
But you were asking for simple ASCII output. For such
simple tasks there are much simpler ways of processing
XML data.

If your only tool is XSLT, everything looks like a template.
Jul 20 '05 #4
Jürgen Kahrs <Ju*********************@vr-web.de> writes:
FlickChick wrote:
I don't usually post questions, but 2 days of googleing and frustration
have broken my resistance.


Who told you to use XSLT for such a simple task ?


It doesn't seem an unreasonable suggestion. The XSLT is shorter and
arguably simpler that the XMLgawk that you posted. (It's hard for me to
say if it really is simpler as I read XSLT a lot better than I read AWK)
It is certainly true that the XSLT is likely to be more portable. It
is hard to find a mchine without at least one XSLT engine installed these
days (anything with IE or mozilla or netscape browsers for example)
but XMLgawk is I would guess rather less available, although no doubt it
may be easily downloaded/installed.

David
Jul 20 '05 #5
David Carlisle wrote:
It is certainly true that the XSLT is likely to be more portable. It
is hard to find a mchine without at least one XSLT engine installed these
days (anything with IE or mozilla or netscape browsers for example)
Really ? Is there an XSL processor inside the browser ?
I always thought that the XML processing is usually
done on the server side.
but XMLgawk is I would guess rather less available, although no doubt it
may be easily downloaded/installed.


That's true, XMLgawk is only experimental.
But there are other tools with larger support
for handling XML files from the command line
(xmlstarlet, IIRC).
Jul 20 '05 #6
Really ? Is there an XSL processor inside the browser ?
I always thought that the XML processing is usually
done on the server side.

yes mozilla family browsers have xslt built in, and IE6 comes
automatically set up to use msxml if served an xml file, and msxml
includes an xslt engine. Not to mention the various java and python
and ... implementations.

David

Jul 20 '05 #7
David Carlisle wrote:
yes mozilla family browsers have xslt built in, and IE6 comes
automatically set up to use msxml if served an xml file, and msxml
includes an xslt engine. Not to mention the various java and python
Interesting.

But the original question started with a command-line
application which should have produced this output:
Which I would like to transform into this:
John,Doe,14
Jane,Smith,15


No mention of a browser here.
Anyway, the user has to decide which tool he wants.
Jul 20 '05 #8

No mention of a browser here.
Quite. You can call msxml from the command line (you have to build
transformiix (mozilla xslt) from source if you want it stand alone) but
my comment was not really to the original poster (I'd already replied to
the XSLT question) but rather to your suggestion that XSLT was a bad
choice for this kind of transformation. I only mentioned the browser
implementations as they give an indication of just how widely installed
XSLT is.
Anyway, the user has to decide which tool he wants.

agreed.

David
Jul 20 '05 #9
David Carlisle wrote:
Really ? Is there an XSL processor inside the browser ?
I always thought that the XML processing is usually
done on the server side.

yes mozilla family browsers have xslt built in, and IE6 comes
automatically set up to use msxml if served an xml file, and msxml


Have a look at this XSLT bug:

http://lkml.org/lkml/2005/1/22/

XSLT error: XML parser error 4: not well-formed (invalid token)
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="_#_TEMPLATE_#_"?><list><title>22 Jan

At least this example looks like the XSLT is
still running on the server side. I guess that
browsers with client side XSLT processing are
still a minority.

I know that this question has nothing to do with
the original news thread, but I found your comment
about client side XSLT processing quite interesting.
Jul 20 '05 #10

<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="_#_TEMPLATE_#_"?><list><title>22 Jan

At least this example looks like the XSLT is
still running on the server side. I guess that

No xml-stylesheet PI (almost) always refers to client side xslt.
Try view source, you'll see the client has the XML source not the
transform.
I guess that
browsers with client side XSLT processing are
still a minority.
I think Opera and safari (for example) are important browsers without
XSLT, but I think that you will find that Internet explorer and
mozilla/netscape/firefox between them account for a large percentage of
desktop browser usage (well in excess of 90%) this is hardly a minority.

Have a look at this XSLT bug:
http://lkml.org/lkml/2005/1/22/


Not sure what you mean here that page (I looked in firefox and IE)
doesn't have any XML or client side transformation. It may as you say be
a server side transform but I can't of course see that from the outside.

David
Jul 20 '05 #11
David Carlisle wrote:
No xml-stylesheet PI (almost) always refers to client side xslt.
Try view source, you'll see the client has the XML source not the
transform.


If PIs are used, I guess that client side XSLT
is not standardized (is it ?).
Have a look at this XSLT bug:
http://lkml.org/lkml/2005/1/22/

Not sure what you mean here that page (I looked in firefox and IE)
doesn't have any XML or client side transformation. It may as you say be
a server side transform but I can't of course see that from the outside.


This is a server side XSLT. They obviously have fixed the server.
Therefore, the error message I saw yesterday does not occur anymore.
Jul 20 '05 #12

If PIs are used, I guess that client side XSLT
is not standardized (is it ?).


The PI in the fragment you quoted is the format of a W3C recommendation
and supported by all Browsers with XSLt (as well as many command line
xslt prograns such as saxon)

David
Jul 20 '05 #13
David Carlisle wrote:
The PI in the fragment you quoted is the format of a W3C recommendation
and supported by all Browsers with XSLt (as well as many command line
xslt prograns such as saxon)


Agreed, I admit that I wrote my question in
a stupid was.

What is not clear to me is, who decides if
the XSLT is to be executed on the client side
or the server side ?

Thanks for your patience.
Jul 20 '05 #14

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

Similar topics

1
by: Otto Porter | last post by:
/*Given*/ CREATE TABLE ( IDENTITY (1, 1) NOT NULL , NULL , (2) NULL , NULL , CONSTRAINT PRIMARY KEY CLUSTERED (
2
by: Soren Kuula | last post by:
Hi, I'm trying to teach myself a little XSL. I have made up an XML model of a consed list, like : <list> <car>a</car> <cdr> <list> <car>b</car>
3
by: rdraider | last post by:
I'm doing a data conversion project, moving data from one SQL app to another. I'm using INSERT INTO with Select and have the syntax correct. But when executing the script I get: Server: Msg...
2
by: Daniel Lidström | last post by:
Hi, I would like to know the cleanest way to change the serialization of my Line class from: <Line staStart="2327.02" length="10.00000003390744"> <End>549016.570965 57945.741122</End>...
1
by: Thu | last post by:
Hi, I create a Dataset to link three tables in my Access database. E.g. The three tables are , , . I then create 2 DataRelations, 1st relation (Order_Cust_Rel) links and using CustomerID field...
6
by: Allan M. Bruce | last post by:
I just recently took a C programming test (which was a total farce - but thats not the point). The code below is a combination of two questions that were included in the test and I was hoping to...
2
by: mmcquade | last post by:
Hey gang, I just created a crosstab query to assist in generating reports for class attendance. When I run the report (using temp hard-coded date constraints), I notice that my column...
8
by: Alec MacLean | last post by:
Hi, I'm using the DAAB Ent Lib (Jan 2006) for .NET 2.0, with VS 2005 Pro. My project is a Web app project (using the WAP add in). Background: I'm creating a survey system for our company, for...
39
by: Alan Isaac | last post by:
This may seem very strange, but it is true. If I delete a .pyc file, my program executes with a different state! In a single directory I have module1 and module2. module1 imports random and...
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
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...
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
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,...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.