473,396 Members | 2,068 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.

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 2142
<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:value-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:otherwise>
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
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
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...
9
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...
10
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. ...
6
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...
3
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...
8
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...
2
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...
1
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...

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.