Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 3rd, 2008, 04:24 AM
Registered User
 
Join Date: Apr 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT and the if condition

Can anybody help me to do an if condition with two conditions?

Something like this:

<xsl:test if test="@attr=657483" and test!=text()">
(I mean if there is that attr and it is not empty)

For empty I mean: <cd attr="657483">IF IH HERE TEXT OR NOT</cd>

is it possible to do it in XSLT?

thank you,

Emilia

 
Old April 3rd, 2008, 04:31 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sorry, I don't understand your problem. Are you having trouble formulating each of the conditions, or combining them into one?

When you say:

For empty I mean: <cd attr="657483">IF IH HERE TEXT OR NOT</cd>

I haven't a clue what you mean.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 3rd, 2008, 04:42 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I think you mean:

<xsl:if test="@attr=6574483 and text()=''">

More on XPath operators here: http://www.w3schools.com/Xpath/xpath_operators.asp

/- Sam Judson : Wrox Technical Editor -/
 
Old April 3rd, 2008, 09:23 AM
Registered User
 
Join Date: Apr 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Sam!

You understand me! Thank you!!!

But in the if condition I want to say:

<xsl:if test="@attr='0040A160' and text()!=''">

when in not empty!

Any clue? if I put the ! operator it gives an error...



 
Old April 3rd, 2008, 10:16 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

It should work. What's the error exactly?

/- Sam Judson : Wrox Technical Editor -/
 
Old April 3rd, 2008, 12:57 PM
Registered User
 
Join Date: Apr 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So, that’s what happen when I do this:

<xsl:for-each select="//item">
    <p><xsl:text>BEGIN</xsl:text></p>
    <xsl:if test="attr/item/attr[@tag='00080104']">
        <p><xsl:text>I AM INSIDE 00080104</xsl:text></p>
        <xsl:if test="attr[@tag='0040A160'] and text()!=''">
            <p><xsl:text>INSIDE 0040A160 THAT EXISTS AND IS NOT EMPTY</xsl:text></p>
            <b><xsl:value-of select="attr/item/attr[@tag='00080104']"/></b><br/>
            <xsl:value-of select="attr[@tag='0040A160']"/>
            <p/>
        </xsl:if>
    </xsl:if>
<p><xsl:text>THE OF THE CICLE</xsl:text></p>
</xsl:for-each>

OUTPUT
BEGIN
THE OF THE CICLE
BEGIN
THE OF THE CICLE
BEGIN
THE OF THE CICLE
BEGIN
THE OF THE CICLE
BEGIN
I AM INSIDE 00080104
THE OF THE CICLE
BEGIN
THE OF THE CICLE
BEGIN
I AM INSIDE 00080104
THE OF THE CICLE
BEGIN
THE OF THE CICLE
BEGIN
I AM INSIDE 00080104
THE OF THE CICLE
BEGIN
THE OF THE CICLE
BEGIN
I AM INSIDE 00080104
THE OF THE CICLE
BEGIN
THE OF THE CICLE
BEGIN
I AM INSIDE 00080104
THE OF THE CICLE
BEGIN
THE OF THE CICLE

It completly ignores that if condition.
If I do 2 separate if:
<xsl:if test="attr[@tag='0040A160']">
       <xsl:if test!="text()''">
the same thing happens, but it gets in the 0040A160 and then ignores the other condition. I've search in internet other way to say that is empty but I didn't find anythig.
Do u have any idea?

Thank very much for help me!

Emilia


 
Old April 3rd, 2008, 04:32 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Try putting the "and text()!=''" inside the predicate:

<xsl:if test="attr[@tag='0040A160' and text()!='']">

This will test the text of the attr element, not the text of the item element.

/- Sam Judson : Wrox Technical Editor -/
 
Old April 3rd, 2008, 06:02 PM
Registered User
 
Join Date: Apr 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

IT WORKS!!!!!:D

Thank you so much!!!!

Emilia:)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent:XSLT element value selection and condition amhicraig XSLT 1 December 4th, 2007 07:57 PM
or condition kgoldvas XSLT 1 July 31st, 2007 03:44 AM
Please help me to create XSLT condition using C# Nick2006 C# 8 July 12th, 2006 06:48 PM
where condition...? mnr555 Crystal Reports 0 June 18th, 2006 05:32 PM
Condition mateenmohd SQL Server 2000 6 May 6th, 2004 03:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.