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 August 14th, 2003, 09:54 AM
Registered User
 
Join Date: Jun 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default conditional output

Its been too long since i read Mikes book from A-Z so this one should be easy for you XSLT sharks out there :D

I want my HTML to only output images if the element <NavigationGraphic> is present. Else i want to output content of <title>.

How do i test if the element NavigationGraphic is empty?

XML:

<Navigation>
       ...
       <NavigationItem ParentId="100" Level="1" ShowInNavigation="true" Selected="false" Expanded="false" LoginRequired="false">
           <PageId>101</PageId>
           <Title>The page title</Title>
           <Url>sw101.asp</Url>
           <NavigationGraphic>Url to the navigation graphic</NavigationGraphic>
           <NavigationGraphicMouseOver>Url to the navigation graphics mouse-over image</NavigationGraphicMouseOver>
           <NavigationSelectedGraphic>url to the selected navigation graphic</NavigationSelectedGraphic>
           <NavigationSelectedGraphicMouseOver>url to the selected navigation graphics mouse-over image</NavigationSelectedGraphicMouseOver>
       </NavigationItem>
       ...
   </Navigation>

XSLT:
<xsl:template match="/Navigation">
...
<xsl:apply-templates select="NavigationItem[@Level='1' and @ShowInNavigation='true']"/>
...
</xsl:template>

<xsl:template match="NavigationItem[@Selected='false' and @Level='1' and @Expanded='false']">
...
              <xsl:choose>

                  <xsl:when test="string-length(NavigationGraphic)=0">
                    <xsl:apply-templates select="Title"/>

                </xsl:when>

                <xsl:otherwise>
                    <img>
                        <xsl:attribute name="src">
                               <xsl:value-of select="NavigationGraphic"/>
                        </xsl:attribute>
                        <xsl:attribute name="border">
                               <xsl:value-of select="'0'"/>
                        </xsl:attribute>
                    </img>

                </xsl:otherwise>

            </xsl:choose>
...
</xsl:template>

thanx
Anders
Reply With Quote
  #2 (permalink)  
Old August 15th, 2003, 12:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Nor Hachin, Kotayk, Armenia.
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

Quote:
quote:
I want my HTML to only output images if the element <NavigationGraphic> is present. Else i want to output content of <title>.

How do i test if the element NavigationGraphic is empty?
In fact "<NavigationGraphic> is present" is quite different from "NavigationGraphic is empty". So, here are that 2 XPath expressions:

Code:
<xsl:if test="not(NavigationGraphic)">
   NavigationGraphic element is absent
</xsl:if>


<xsl:if test="normalize-space(NavigationGraphic) = ''">
  NavigationGraphic element's content is empty
</xsl:if>
Regards,
Armen
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
conditional IF roy_mm Reporting Services 0 October 30th, 2006 07:52 AM
Conditional Output on childnodes? fahmyr XSLT 3 September 11th, 2006 11:49 AM
Conditional submit arnabghosh Javascript How-To 1 August 4th, 2005 02:40 AM
Conditional adding spencer.clark XSLT 1 July 28th, 2005 01:19 PM
Datagrid Conditional ~Bean~ ASP.NET 1.0 and 1.1 Basics 3 July 27th, 2005 12:40 AM



All times are GMT -4. The time now is 02:01 AM.


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