Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 3rd, 2006, 11:49 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL Test

Given XML like this:

Code:
<nav>
    <tree>
        <page id="5004" desc="Site" sort="5004">
            <page id="5242" desc="Careers" sort="5242">
                <page id="350231838" desc="Careers Update" sort="350231838">
                    <page id="350231839" desc="September 2005" sort="350231839" />
                </page>    
            </page>
        </page>
    </tree>
    <hidden>
        <page id="350231839" />
    </hidden>
</nav>
I want to transform the pages (please ignore the badly formed XML) into a series of unordered lists, but I don't want to output any elements if they appear in the <hidden> section. My current test before I output the ul is xsl:if "child::page", but this does not properly handle the case where the current element has children, but they all appear in the hidden section. How would I ask (essentially), "If this element has at least one child element 'page' that does not show up in the hidden list"?

Reply With Quote
  #2 (permalink)  
Old February 3rd, 2006, 12:35 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Think you need the not function:
Code:
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"/>

  <xsl:template match="/">
    <html>
      <body>
        [list]
          <xsl:apply-templates select="nav/tree/page[not(@id = /nav/hidden/page/@id)]" />
        </ul>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="page">
    <li>
      <xsl:value-of select="@desc"/>
      <xsl:if test="page[not(@id = /nav/hidden/page/@id)]">
        [list]
          <xsl:apply-templates select="page[not(@id = /nav/hidden/page/@id)]"/>
        </ul>
      </xsl:if>
    </li>
  </xsl:template>
</xsl:stylesheet>
This assumes that when you hit a hidden item it has no more visible children.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old February 3rd, 2006, 02:49 PM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Perfect. Thanks. I didn't know how to reference elements in that way.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:test, but ignoring whitespace mphare XSLT 1 December 5th, 2008 05:23 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:if test="" Question kwilliams XSLT 2 August 9th, 2005 08:30 AM
Using xsl:if test attributes rdavisiii XSLT 4 November 9th, 2004 12:24 AM



All times are GMT -4. The time now is 12:56 PM.


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