473,657 Members | 2,516 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xslt trouble with xsl:if

z1
hi-

i am fooling around with soap and weather templates.
for some reason either this if or select is failing.
i am very new to xml and found this code at another site.
i can show you the xml and then the xslt sample code that is not matching.
please look and if it jumps right off the page give me a tip on why it didnt
select the data.
i think for most xslt people this will be easy. i want the if to work if it
is null because
the weather service may return null for an attribute.

from the government weather service:
<weather time-layout="k-p24h-n5-1">
<name>Weather Type, Coverage, and Intensity</name>
<weather-conditions weather-summary="Increa sing Clouds"/>
<weather-conditions weather-summary="Partly Cloudy"/>
<weather-conditions weather-summary="Partly Cloudy"/>
<weather-conditions weather-summary="Mostly Sunny"/>
<weather-conditions weather-summary="Chance Rain Showers">
<value coverage="chanc e" intensity="ligh t" weather-type="rain
showers" qualifier="none "/>
</weather-conditions>
</weather>
from a sample template i found:
<xsl:template name="weather">
<xsl:param name="position" />
<xsl:if
test="/dwml/data/parameters/weather/weather-conditions[position()=$pos ition]/@weather-summary
!=''">
<xsl:value-of
select="/dwml/data/parameters/weather/weather-conditions[position()=$pos ition]/@weather-summary"/>
</xsl:if>
</xsl:template>

other parts of the templates are generating output (not formatted yet
though)
assuming that the path is correct and it looks like it is, why wont this
match?
@weather-summary is the attribute that has a value associated with it that
is not null.
the path from the root looks ok....

i want to get into learning a little bit more about xml and xslt.
i have a book on it and am currently studing a css book too.
i like the fact that when i combine all the templates with html i can have
it output
the results formatted. i need to get better at the xslt processing.

thanks very much.
i hope you are enjoying the weekend too.
jim (website - 3rdshiftcoder.c om)



Jun 27 '08 #1
3 2344
z1 wrote:
hi-

i am fooling around with soap and weather templates.
for some reason either this if or select is failing.
i am very new to xml and found this code at another site.
i can show you the xml and then the xslt sample code that is not matching.
please look and if it jumps right off the page give me a tip on why it didnt
select the data.
i think for most xslt people this will be easy. i want the if to work if it
is null because
the weather service may return null for an attribute.

from the government weather service:
<weather time-layout="k-p24h-n5-1">
<name>Weather Type, Coverage, and Intensity</name>
<weather-conditions weather-summary="Increa sing Clouds"/>
<weather-conditions weather-summary="Partly Cloudy"/>
<weather-conditions weather-summary="Partly Cloudy"/>
<weather-conditions weather-summary="Mostly Sunny"/>
<weather-conditions weather-summary="Chance Rain Showers">
<value coverage="chanc e" intensity="ligh t" weather-type="rain
showers" qualifier="none "/>
</weather-conditions>
</weather>
from a sample template i found:
<xsl:template name="weather">
<xsl:param name="position" />
<xsl:if
test="/dwml/data/parameters/weather/weather-conditions[position()=$pos ition]/@weather-summary
!=''">
Depending on how the incoming data is handled (parsed as well-formed
only, or validated), position() may evaluate to one of two things:

a) what you intuitively expect (if you're used to normal text document
markup (HTML, DocBook, TEI, etc): the numeric position of the
weather-conditions *element node* among its siblings (eg for
@weather-summary='Partly Cloudy' this would be "2" and "3");

b) what you don't expect (unless you came to XML via the "data-only"
route): the numeric position of the matching node among *all* types of
siblings, including the "name" element and the (otherwise irrelevant)
white-space between the weather-conditions elements (eg for
@weather-summary='Partly Cloudy' this would be "6" and "8").

I'm unclear why it would want to identify the weather-conditions element
by position anyway.

The reliable way of matching location-among-siblings is to use
[count(preceding-sibling::weathe r-conditions)+1=$ position]
<xsl:value-of
select="/dwml/data/parameters/weather/weather-conditions[position()=$pos ition]/@weather-summary"/>
</xsl:if>
</xsl:template>

other parts of the templates are generating output (not formatted yet
though)
assuming that the path is correct and it looks like it is, why wont this
match?
Use xsl-message and xsl:value-of to output the actual value of $position
to the console during execution so you can debug it.
@weather-summary is the attribute that has a value associated with it that
is not null.
the path from the root looks ok....
You haven't shown us the whole document, so we'll take it on trust that
there is a containing structure reflecting /dwml/data/parameters
i want to get into learning a little bit more about xml and xslt.
i have a book on it and am currently studing a css book too.
i like the fact that when i combine all the templates with html i can have
it output
the results formatted. i need to get better at the xslt processing.
Dave Pawson's excellent XSL FAQ (http://www.dpawson.co.uk/xsl/), and
Mulberry's XSL-LIST mailing list
(http://www.mulberrytech.com/xsl/xsl-list/index.html) are your friends.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Jun 27 '08 #2
z1
Hi Peter -

thanks very much for the response.
i need to practice more.
i will save your post and can come
back to it a little later.

i kind of get things but need more work.
thanks for the list of resources at the end
of your post.

jim

"Peter Flynn" <pe********@m.s ilmaril.iewrote in message
news:67******** *****@mid.indiv idual.net...
z1 wrote:
>hi-

i am fooling around with soap and weather templates.
for some reason either this if or select is failing.
i am very new to xml and found this code at another site.
i can show you the xml and then the xslt sample code that is not
matching.
please look and if it jumps right off the page give me a tip on why it
didnt
select the data.
i think for most xslt people this will be easy. i want the if to work if
it
is null because
the weather service may return null for an attribute.

from the government weather service:
<weather time-layout="k-p24h-n5-1">
<name>Weather Type, Coverage, and Intensity</name>
<weather-conditions weather-summary="Increa sing Clouds"/>
<weather-conditions weather-summary="Partly Cloudy"/>
<weather-conditions weather-summary="Partly Cloudy"/>
<weather-conditions weather-summary="Mostly Sunny"/>
<weather-conditions weather-summary="Chance Rain Showers">
<value coverage="chanc e" intensity="ligh t" weather-type="rain
showers" qualifier="none "/>
</weather-conditions>
</weather>
from a sample template i found:
<xsl:templat e name="weather">
<xsl:param name="position" />
<xsl:if
test="/dwml/data/parameters/weather/weather-conditions[position()=$pos ition]/@weather-summary
!=''">

Depending on how the incoming data is handled (parsed as well-formed
only, or validated), position() may evaluate to one of two things:

a) what you intuitively expect (if you're used to normal text document
markup (HTML, DocBook, TEI, etc): the numeric position of the
weather-conditions *element node* among its siblings (eg for
@weather-summary='Partly Cloudy' this would be "2" and "3");

b) what you don't expect (unless you came to XML via the "data-only"
route): the numeric position of the matching node among *all* types of
siblings, including the "name" element and the (otherwise irrelevant)
white-space between the weather-conditions elements (eg for
@weather-summary='Partly Cloudy' this would be "6" and "8").

I'm unclear why it would want to identify the weather-conditions element
by position anyway.

The reliable way of matching location-among-siblings is to use
[count(preceding-sibling::weathe r-conditions)+1=$ position]
> <xsl:value-of

select="/dwml/data/parameters/weather/weather-conditions[position()=$pos ition]/@weather-summary"/>
</xsl:if>
</xsl:template>

other parts of the templates are generating output (not formatted yet
though)
assuming that the path is correct and it looks like it is, why wont this
match?

Use xsl-message and xsl:value-of to output the actual value of $position
to the console during execution so you can debug it.
>@weather-summary is the attribute that has a value associated with it
that
is not null.
the path from the root looks ok....

You haven't shown us the whole document, so we'll take it on trust that
there is a containing structure reflecting /dwml/data/parameters
>i want to get into learning a little bit more about xml and xslt.
i have a book on it and am currently studing a css book too.
i like the fact that when i combine all the templates with html i can
have
it output
the results formatted. i need to get better at the xslt processing.

Dave Pawson's excellent XSL FAQ (http://www.dpawson.co.uk/xsl/), and
Mulberry's XSL-LIST mailing list
(http://www.mulberrytech.com/xsl/xsl-list/index.html) are your friends.

///Peter
--
XML FAQ: http://xml.silmaril.ie/

Jun 27 '08 #3
z1
Hi again Peter-

I am finally getting this stuff better.

What had me stuck was that somehow the file i had copied from the government
web server for the weather wasnt quite right. you can put in all the xpath
and
xslt you want but if the xml file is broken that you are basing it on you
are
nowhere. i must not have copied it just right or hit a key by mistake
and saved it.

i found that if i keep the command line open in windows and run
saxon after i make changes in the phpedit environment it is blazing
fast and gives me good tips on where to fix the problems.

i wont need that other persons code once i get going.
i am going to make the weather forecast fancier on my site when
i get the time.

thanks so much for helping,
jim
Jun 27 '08 #4

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

Similar topics

3
1206
by: Steven | last post by:
I'm using XSL to transform an XML document to HTML, however I'm encountering the following problem.I want to test a couple of values using an xsl:if statement and then print a couple of HTML tags only when the condition is met: <xsl:if test="position() = $countPar"> </td> <td width="50%" valign="top">
3
3893
by: Lizard | last post by:
OK, total newbie here, so this may be a mind-numbingly dumb question AND I may be phrasing it badly. I have an xsl:template which looks like this: <xsl:template match="LoanRecord"> <hr> <xsl:number count="LoanRecord" format="1"/><br/> Loan ID:<xsl:value-of select="loan_no"> </xsl:value-of><br/> Calculated CLTV:<xsl:value-of select="format-number (curr_balance div
9
8314
by: Andrea Maschio | last post by:
Hi, i have a terrible noobie frustration formatting an XML file like this: <Dipendente Id="1" Anno="2003" Nome="pippo" Cognome="pippi" Nato_il="10/03" Email="pippo@emailprovider.it" Esito="ok"/> On the XSLt file relayed to this XML, i wrote in green the attribute value if Attribute "Esito" is "Ok". I mean, something, like this:
3
3596
by: Eric Theil | last post by:
I'm at my wit's end with this one. Within an xsl:if test, I'm not able to get 2 variables to properly evaluate if one of them is wrapped within a string function. <!-- This works --> <xsl:if test="$var:v141=&quot;true&quot;"> <!-- This doesn't work --> <xsl:if test="string($var:v141)=&quot;true&quot;">
5
2331
by: Luke Vogel | last post by:
Hi all, Probably a really basic question, but I cant find an answer ... I have an xml file of books something like: <product> <isbn>0-735-61374-5</isbn> <title>Microsoft Visual Basic Step By Step</title> <author>Michael Halvorsen</author> <subject>Programming</subject>
3
14276
by: tldisbro | last post by:
Hello All, I am trying to use the returned value of the <fo:page-number> element/function in my <xsl:if> test condition. But am unsuccessful in doing so. Is it possible to use it in this fashion with a conversion or correct syntax? I would like to test the current page number and see if it is even or odd - and if it is odd I would like to perform additional steps. I would like to do something like this (assume all namespaces are set):...
1
1813
by: Fred | last post by:
Hi, I am using XSL if to look and see if a node exists and if so display it with a header (see below). Some of the xml I transforming has nodes like this <Test /and it shows up in my html report (header no value). How do I test for this? <xsl:if test="Test"> <xsl:if test="Test"> <b><xsl:text>Header: </xsl:text></b>
4
2966
by: Doulos05 | last post by:
Ok, this seems like it should be easy, but it has escaped me. Here is my xml file: <ref_sheet> <item> <date>2007/04/06</date> <product>124567</product> <description>TAB DIVIDERS</description> <note>Description of problem here</note>
1
5064
by: cfli1688 | last post by:
I saw example of xsl:if and I want to use it. I know that &gt; is greater than. Is there one for equals to, I try &eq; and it does not recognize it. Where can I get a list for this? Also, I have the following: <xsl:variable name="oldID" select="oldid"/> <xsl:variable name="currID" select="id"/> <xsl:choose> <xsl:when test="$currID != $oldID">>
0
8324
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
8842
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
8617
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
7353
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
6176
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
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.