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 9th, 2007, 12:44 PM
Registered User
 
Join Date: Oct 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Nested Choose

Snippet
<xsl:when test="@Type='13'">
                  <xsl:choose>
                    <xsl:when test="/Categories[@Id]='352'">
                      <a target="_self">
                        <xsl:attribute name="href">
                          default.aspx?Page=141&amp;category.Categories.1=<x sl:value-of select="Categories/@Id"/>&amp;centerContent.Id.0=<xsl:value-of select="@Id"/>
                        </xsl:attribute>

                        <xsl:value-of select="@Name"/>
                      </a>
                    </xsl:when>
                    <xsl:otherwise>
                      <a target="_self">
                        <xsl:attribute name="href">
                          default.aspx?Page=75&amp;category.Categories.1=<xs l:value-of select="Categories/@Id"/>&amp;centerContent.Id.0=<xsl:value-of select="@Id"/>
                        </xsl:attribute>

                        <xsl:value-of select="@Name"/>
                      </a>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>

Based on the following XML:
<Root>
  <AnyContent Id="10223" Name="About the Falls Clinic" Type="13" Owner="371" Description="A comprehensive, interdisciplinary assessment and rehabilitative outpatient treatment program." DatePublished="2007-05-23T13:28:06.997" EffectiveDate="1900-01-01T00:00:00" ExpiryDate="2079-01-01T00:00:00">
    <Categories Id="95" Name="Geriatric Day Hospital and Falls Clinic" />
  </AnyContent>
  <AnyContent Id="17160" Name="Adult Medical - Surgical Nursing Program" Type="13" Owner="4386" Description="The Adult Medical-Surgical Nursing Program (AMSNP) is a performance-based certification program that prepares registered nurses for the professional practice of medical-surgical nursing. " DatePublished="2007-07-17T10:31:54.130" EffectiveDate="1900-01-01T00:00:00" ExpiryDate="2079-01-01T00:00:00">
    <Categories Id="352" Name="Registered Nurses Professional Development Centre (RNPDC)" />
  </AnyContent>
  <AnyContent Id="5736" Name="Adult Medical-Surgical Nursing Program Content Outline" Type="5" Owner="4386" Description="Adult Medical-Surgical Nursing Program Content Outline" DatePublished="2007-04-27T14:34:14.137" EffectiveDate="1900-01-01T00:00:00" ExpiryDate="2079-01-01T00:00:00">
    <Categories Id="352" Name="Registered Nurses Professional Development Centre (RNPDC)" />
  </AnyContent>
</Root>

I'm having an issue in my XSL on my 2nd when condition. It is skipping over the condition /Categories[@Id]='352' and going directly to the otherwise statement when the category is 352. What am i missing here?

The desired output would be to render the first condition instead of bypassing it to the otherwise. I am running on WinXP and using MS Visual Web Dev. Express.
 
Old November 9th, 2007, 01:24 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's that "/". When you write "/Categories", you're referring to a Categories element that's the outermost element of the document.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 9th, 2007, 01:26 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

What your current xpath pattern is test for is - get me all the top level elements whose name is 'Categories' and have an 'Id' attribute, and then see if any of them equal '352' (the Categories, not the Id attribute).

It should read "Categories[@Id='352']" which gets you a child element called Categories whose 'Id' attribute has a value of '352'.


/- Sam Judson : Wrox Technical Editor -/
 
Old November 9th, 2007, 01:27 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Incidentally, you can write this:

<a target="_self">
                        <xsl:attribute name="href">
                          default.aspx?Page=141&amp;category.Categories.1=<x sl:value-of select="Categories/@Id"/>&amp;centerContent.Id.0=<xsl:value-of select="@Id"/>
                        </xsl:attribute>

                        <xsl:value-of select="@Name"/>
                      </a>

as:

<a target="_self"
  href=" default.aspx?Page=141&amp;category.Categories.1={C ategories/@Id}&amp;centerContent.Id.0={@Id}">
     <xsl:value-of select="@Name"/>
</a>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 9th, 2007, 01:44 PM
Registered User
 
Join Date: Oct 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for the help guys.

one last question. is it possible to put an OR clause in my test="Categories[@Id='352'" kind of like you would in an SQL statement? or values seperated by a pipe or something.

 
Old November 9th, 2007, 01:48 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

http://www.w3schools.com/xpath/xpath_operators.asp

[a or b]

/- Sam Judson : Wrox Technical Editor -/
 
Old November 9th, 2007, 03:24 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Yes, the "or" operator in XPath is spelt "or", just like in SQL.

XPath also has a "|" operator which corresponds to "union" in SQL. You can sometimes use it interchangeably with "or", for example

a[@x or @y]

means the same as

a[@x|@y]

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
choose between two directories and use one jjk2 PHP How-To 1 June 3rd, 2008 05:07 PM
Both "when" hit in choose estranda XSLT 2 June 18th, 2007 09:02 AM
Choose all by date? morpheus SQL Server ASP 3 July 30th, 2005 11:50 PM
xsl:choose djmarquette XSLT 5 March 29th, 2005 11:44 AM
"choose, when, otherwise" - problem natjimy XSLT 8 December 17th, 2004 02:22 PM





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