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

Home Posts Topics Members FAQ

how to extract from _inside_ xml tag

here's my xml:

<dimension name="lat" units="degrees_ north"
dim_type="index ">
<min>-90</min>
<max>90</max>
<count>181</count>
</dimension>
<dimension name="lon" units="degrees_ east"
dim_type="index ">
<min>-180</min>
<max>179</max>
<count>360</count>
</dimension>
I'm having difficulty finding out which of these tags are name="lat"
and which are name="lon".
right now I have:
<xsl:for-each select="/dataset/LatLonTimeCube/dimensions/
dimension">
<xsl:if test="name=lon" >
&lt;westbc&gt;< xsl:value-of select="min"/>&lt;/westbc&gt;
&lt;eastbc&gt;< xsl:value-of select="max"/>&lt;/eastbc&gt;
</xsl:if>
<xsl:if test="name=lat" >
&lt;northbc&gt; 90&lt;/northbc&gt;
&lt;southbc& gt;-90&lt;/southbc&gt;
</xsl:if>
</xsl:for-each>

I know the 90 in there is a constant, I was just testing.

For the above xml, I need to print out:

west: -179
north: 90
east: 180
south: -90

BUT, my if test="name=lon" is always failing. Does anyone know how to
test the value of name from inside the dimension tag?

I would extremely appreciate any help.
Thanks!
-Ed

Jun 29 '07 #1
7 2152
<xsl:if test="name=lon" >

That compares the value of the <namechild element against the value of
the <lonchild element -- which of course doesn't exist. Change it to

<xsl:if test="name='lon '">

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Jun 29 '07 #2
Hey Joe thanks, but it still doesn't seem to be passing the test.

<xsl:if test="name='lon '">
&lt;westbc&gt;< xsl:value-of select="min"/>&lt;/westbc&gt;
&lt;eastbc&gt;< xsl:value-of select="max"/>&lt;/eastbc&gt;
</xsl:if>

<xsl:if test="name='lat '">
&lt;northbc&gt; 90&lt;/northbc&gt;
&lt;southbc& gt;-90&lt;/southbc&gt;
</xsl:if>

doesn't output anything because it's still failing the test.
If I change the ifs to a choose/otherwise, the otherwise is getting
printed, because it's failing the test.

Any other ideas?

Jun 29 '07 #3
By the way,
&lt;westbc&gt;< xsl:value-of select="min"/>&lt;/westbc&gt;
is *****EXTREMELY* **** bad practice. If you want to construct XML
output, use literal XML or the appropriate XSLT directives.

<westbc><xsl:va lue-of select="min"/></westbc>
or
<xsl:element name="westbc">< xsl:value-of select="min"/></xsl:element>
As to why things aren't matching: I'll take another look, but I suspect
you've given us an incomplete description of your problem.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Jun 29 '07 #4
Ya, I've never used XSL before, my co-worker has come to me with this
problem hoping I can help. I'll make her change her output structure.

As for my problem, I'm not sure what else to include. i can't attach
files, but basically I've got:

<dimension name="lat" units="degrees_ north"
dim_type="index ">
<min>-90</min>
<max>90</max>
<count>181</count>
</dimension>
<dimension name="lon" units="degrees_ east"
dim_type="index ">
<min>-180</min>
<max>179</max>
<count>360</count>
</dimension>

and:

<xsl:for-each select="/dataset/LatLonTimeCube/dimensions/dimension">
<xsl:choose>
<xsl:when test='name="lat "'>
SUCCESS!
</xsl:when>
<xsl:otherwis e>
failed
</xsl:otherwise>
</xsl:choose>

should output one SUCCESS and one failed, but it's always failed.
I would be happy to host these 2 files on my server so anyone could
take a look at them if they wish.

Jun 29 '07 #5
edfialk wrote:
As for my problem, I'm not sure what else to include.
Including a minimal runnable example is usually a good idea -- a
complete input file, and a complete stylesheet, both trimmed down to
absolute essentials needed to demonstrate the problem.
I would be happy to host these 2 files on my server so anyone could
take a look at them if they wish.
If they're short enough that we don't get bogged down in irrelevant
detail, that will do the job. If not, trim 'em down first, them post.

(Among other things, the process of trying to reduce the problem to its
simplest form is often enough by itself to expose the mistake.)
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Jun 29 '07 #6
Joseph Kesselman schrieb:
> <xsl:if test="name=lon" >

That compares the value of the <namechild element against the value of
the <lonchild element -- which of course doesn't exist. Change it to

<xsl:if test="name='lon '">
As name is an attribute, it must be "@name='lon '" instead.
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
Jun 29 '07 #7
As name is an attribute, it must be "@name='lon '" instead.

Blush. Can't believe I missed that typo...

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Jun 29 '07 #8

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

Similar topics

4
3278
by: Don Crossman | last post by:
Assume a MYSQL table, foo. One column, bar datetime. Two rows: 2004-01-01 08:00:00 2004-02-01 08:00:00 select * from foo where extract(day from bar)=1; 2 rows in set...
3
3932
by: Phong Ho | last post by:
Hi everyone, I try to write a simple web crawler. It has to do the following: 1) Open an URL and retrieve a HTML file. 2) Extract news headlines from the HTML file 3) Put the headlines into a RSS file. For example, I want to go to this site and extract the headlines: www.unstrung.com/section.asp?section_id=86
9
16995
by: Sharon | last post by:
hi, I want to extract a string from a file, if the file is like this: 1 This is the string 2 3 4 how could I extract the string, starting from the 10th position (i.e. "T") and extract 35 characters (including "T") from a file and then go to next line?
10
8675
by: Robert Schultz | last post by:
I have a C/C++ file that I simply want to 'extract' a function from. Something like: extract <function name> <c or cpp file> I want it to return from the beginning of the function, to the end. I tried cscope, and that will find the function, but it won't tell me how many lines it is or extract it for me. Any ideas on what I could use?
6
10519
by: Mohammad-Reza | last post by:
Hi I want to extract icon of an exe file and want to know how. I look at the MSDN and find out that I can use ExtractIconEx() Windows API but in there are some changes to that api in c# I made those changes like this : public static extern uint ExtractIconEx( string szFile,
3
5061
by: jarod1701 | last post by:
Hi, I'm currently trying to create a regular expression that can extract certain elements from a url. The url will be of the following form: http://user:pass@www.sitename.com I want a regex that matches the "user" part of that url.
8
2847
by: Fabian Braennstroem | last post by:
Hi, I would like to remove certain lines from a log files. I had some sed/awk scripts for this, but now, I want to use python with its re module for this task. Actually, I have two different log files. The first file looks like: ...
2
2660
by: kimi | last post by:
Hi ppl, I am new to PHP. I would need some information on the following: 1. a) I wanted to know from where the data is extracted and stroed in the global assocoative arrays ( specifically what will be the contents of $_Session ?) b) Is there any way by which i can get to know all the keys of the arrays ( specifically what are the Keys of $_Session ?)
1
4582
by: rcamarda | last post by:
I'd need to have a function that allows me to extract 'fields' from within the string I.E. (kinda pseudo code) declare @foo as varchar(100) set @foo = "Robert*Camarda*123 Main Street" select EXTRACT(@foo, '*', 2) ; -- would return 'Camarda' select EXTRACT(@foo, '*', 3) ;-- returns '123 Main Street' select EXTRACT(@foo, '*', 0) ;-- would return entire string select EXTRACT(@foo,'*' , 9) ;-- would return null
5
5776
by: Steve | last post by:
Hi all Does anybody please know a way to extract an Image from a pdf file and save it as a TIFF? I have used a scanner to scan documents which are then placed on a server, but I need to extract the image of the document (just the first page if there are multiple pages) and save it as a TIFF so I can then use the Tesseract OCR to get the text in the image.
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...
0
10403
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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
5978
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4597
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4196
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.