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 November 5th, 2004, 02:49 PM
Registered User
 
Join Date: Nov 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rdavisiii
Default Using xsl:if test attributes

I am trying to setup some xml out put. I am doing some conditional test using xsl:if. I seem to be having an issue with testing attributes. Below is the input and my xsl to do the conversion.I amm ok up til I attempt to test the attribute. What am I doing wrong.


XML

<widjet><name>ActiveCall</name><type>List</type><values><XML><TR X1="33" Y1="3" X2="157" Y2="16"><TD X1="33" Y1="3" X2="157" Y2="16">Status</TD><TD X1="163" Y1="3" X2="391" Y2="16">Last Updated</TD><TD X1="397" Y1="3" X2="542" Y2="16">Contact</TD><TD X1="548" Y1="3" X2="821" Y2="16">Communications</TD><TD X1="827" Y1="3" X2="971" Y2="16">Subject</TD></TR><TR X1="163" Y1="23" X2="391" Y2="39"><TD X1="33" Y1="23" X2="157" Y2="39">Today</TD><TD X1="163" Y1="23" X2="391" Y2="39">11/05/04 11:21 AM</TD><TD X1="397" Y1="23" X2="542" Y2="55">Steve Johnson
Home Depot</TD><TD X1="548" Y1="23" X2="821" Y2="55">(Assistant Phone)
(603) 879-5641</TD><TD X1="827" Y1="23" X2="971" Y2="39">Orange is ok</TD></TR><XML>
</values></widjet>


xsl

<xsl:if test="name='ActiveCall'">
<xsl:if test="type='List'">
<xsl:if test="values/xml/TR/ @Y1'&gt;10'">
     <calllist>
<xsl:for-each select="values/XML/TR">
<call>
<status><xsl:value-of select="TD[position()=1]"/></status>
<followup><xsl:value-of select="TD[position()=2]"/></followup>
<contact><xsl:value-of select="TD[position()=3]"/></contact>
<communication><xsl:value-of select="TD[position()=4]"/></communication>
<subject><xsl:value-of select="TD[position()=5]"/></subject>
    </call>
</xsl:for-each>
    </calllist>
    </xsl:if>
</xsl:if>
</xsl:if>
 
Old November 5th, 2004, 03:40 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

<xsl:if test="values/xml/TR/@Y1 &gt; 10 ">
this line tests if the Y1 attribute of the first TR element of the first xml element of ... is greater than 10.
Since the first one isn't (the header line has Y1=3), you won't get any output from there on.

Not sure what you want exactly, could be intepreted several ways.
If you only want to output a table if there is a Y1 attribute greater than 10, then you can use the conditional statement:
test="values/xml/TR[@Y1 &gt; 10]"
checks TR elements until we find a matching one or have checked all TR elements.

If you only want to list the ones with Y1 attribute > 10, then change your for-each loop to something like:
<xsl:for-each select="values/XML/TR[@y1 gt; 10]">
 
Old November 5th, 2004, 03:53 PM
Registered User
 
Join Date: Nov 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rdavisiii
Default

I see,

I want to disregard the ones that are less then 10 and output the ones more then 10. The ones less then 10 are headers in this case and not needed, the rest is passed back to be used in html output.

Thanks


 
Old November 5th, 2004, 05:26 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

then you definitely want to add the [@y1 gt; 10] condition to your for-each loop.

If you have an empty table (just the header) did you want to output the table at all? (eg. it just'd be an empty <calllist/> tag.)

 
Old November 9th, 2004, 12:24 AM
Registered User
 
Join Date: Nov 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rdavisiii
Default

With the headers remove, I use the values(contacts) in a hyperlink. On the html output it generates a list of names, each is a hyperlink when clicked will access details about that contact. Your advice helped me greatly, I am very new to xsl and xml for that matter and somtimes(most times) I am very confused.

Thanks again






Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:when test - comparison problem pelicanPaul XSLT 1 June 29th, 2007 04:45 AM
XSL Params inside When Test shasto100 XSLT 3 April 21st, 2006 05:45 AM
Sorting a xsl:if test="position()" charmaigne XSLT 2 April 12th, 2006 04:42 AM
XSL Test tclancy XSLT 2 February 3rd, 2006 02:49 PM
<xsl:if test="" Question kwilliams XSLT 2 August 9th, 2005 08:30 AM





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