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 August 14th, 2003, 09:54 AM
Registered User
 
Join Date: Jun 2003
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
 
Old August 15th, 2003, 12:01 AM
Friend of Wrox
 
Join Date: Jun 2003
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





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





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