469,332 Members | 6,612 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

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 2064
<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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Don Crossman | last post: by
3 posts views Thread by Phong Ho | last post: by
9 posts views Thread by Sharon | last post: by
10 posts views Thread by Robert Schultz | last post: by
6 posts views Thread by Mohammad-Reza | last post: by
8 posts views Thread by Fabian Braennstroem | last post: by
2 posts views Thread by kimi | last post: by
1 post views Thread by rcamarda | last post: by
5 posts views Thread by Steve | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.