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 10th, 2006, 12:44 AM
Registered User
 
Join Date: Apr 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem with xsl:if

hi ,

i am slightly new to xsl and i 'm having a difficult time understanding the following problem. the relevant part of my xml is like this:
....
<book>
  <removed>y</removed>
  <author >asds</author>
<title>ccc</title>
.....
</book>

i have a xsl which has something like
<xsl:template name="Outputields">
        <xsl:param name="nodes"/>

<xsl:for-each select="$nodes">
        <xsl:if test="descendant::*[name()!='removed']" >


blah ...blah..

</xsl:if>
</xsl:for-each>
.......

where $nodes is a variable that gets the value book/* passed to it.

my problem is i get the removed element also in my output.
how does that happen?? any help pls????

Namz
 
Old April 10th, 2006, 02:53 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I suspect you haven't shown us enough of your code.

Your test is pretty odd, though. If $nodes consists of the children of <book>, then it contains the three elements <removed>, <author>, and <title>. None of these have a descendant element; therefore none of them have a descendant element whose name is not "removed"; therefore none of them satisfy the test in your xsl:if.

If you're trying to process all the $nodes except the <removed> element, the way to do that is

xsl:for-each select="$nodes[not(self::removed)]"



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 10th, 2006, 03:25 AM
Registered User
 
Join Date: Apr 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi..
thx for the reply.
what i want to do is if there is a removed element as a child in book none of the other child elements should be in the output.

to give the other part of the code..
<xsl:template name="Outputields">
        <xsl:param name="nodes"/>

<xsl:for-each select="$nodes">
        <xsl:if test="descendant::*[name()!='removed']" >


<tr>
<td bgcolor="#EEEEEE">
<span class="column">
                                    <xsl:value-of select="name()"/>

    </span>
</td>
</tr>

</xsl:if>
</xsl:for-each>

.

Namz
 
Old April 10th, 2006, 03:55 AM
Registered User
 
Join Date: Apr 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the xml has two decendent nodes in removed..

<removed>
<from></from>
<to></to>
</removed>

 
Old April 10th, 2006, 03:57 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>What i want to do is if there is a removed element as a child in book none of the other child elements should be in the output.

That sounds like

<xsl:choose>
  <xsl:when test="$nodes[self::removed]">
    ... there is a "removed" element. Process it... (or do nothing?)
  </xsl:when>
  <xsl:otherwise>
    <xsl:for-each select="$nodes">
      .. there is no "removed" element, so process all the nodes ...
    </xsl:for-each>
  </xsl:otherwise>
</xsl:choose>

I don't see where you got the idea of using the descendant axis: you seem to have some misunderstanding of basic concepts, and spending some time with a good book or tutorial would probably help.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL for-each/when problem Grofit XSLT 11 March 27th, 2008 10:26 AM
XSL problem cheez XSLT 1 September 14th, 2006 01:20 AM
Problem with XSL sandeepa XSLT 5 May 13th, 2005 04:31 AM
Help with xsl:when problem sundar_revathi XSLT 2 November 9th, 2004 07:39 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





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