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 7th, 2003, 10:13 AM
Registered User
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default conditional statement based on attribute value

I'm trying to figure how to write a conditional statement in XSLT that will do one thing if a node attribute starts with a T and another thing if it starts with an M.

<member name="T:IHDomainElementManager">
  <summary>IHDomainElementManager Interface</summary>
</member>
<member name="M:Elements(HObject Param0, HObject Param1)">
  <summary>property Elements</summary>
</member>


I know my XSLT will look something like this:
<xsl:choose>

<xsl:when test=starts-with(@name,'T:H')>
    ...do something

but it's not matching on the test.

Thanks for your help.
Daniel


 
Old November 7th, 2003, 11:15 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

If you want to detect whether the name attribute starts with "T" or "M", write:

Code:
<xsl:choose>
 <xsl:when test="starts-with(@name,'T')">
    ...do something
 </xsl:when>
 <xsl:when test="starts-with(@name,'M')">
    ...do something
 </xsl:when>
</xsl:choose>
In your example you wrote test=starts-with(@name,'T:H')... and also the example is not a well-formed XML(quots are missing for attribute value).

Regards,
Armen
 
Old November 7th, 2003, 12:50 PM
Registered User
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ahhh, I knew it was going to be something like that. Missing quotes.

Thank you very much. Worked beautifully.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with conditional sql statement MarkGT Classic ASP Basics 11 May 6th, 2008 08:41 PM
conditional xslt processing based on java array twilson997 XSLT 7 June 28th, 2006 07:32 AM
Match element based on attribute of child? transom XSLT 1 September 11th, 2005 03:26 PM
Conditional IF statement iloveoatmeal Classic ASP Basics 5 July 20th, 2005 08:33 PM
Rules based on attribute values... jacob XML 2 July 6th, 2005 01:50 PM





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