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 November 17th, 2004, 07:14 AM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL:CHOOSE & XPATH

Depending on an already defined variable value, I'd like to set the value of a variable to an XPath. For example:

<xsl:variable name="xpath">
<xsl:choose>
<xsl:when test="$parent != 0">$structure/structure/*/*[@id = name(current())]</xsl:when>
<xsl:otherwise><xsl:value-of select="$structure/structure/*[@id = name(current())]</xsl:otherwise>
</xsl:choose>
</xsl:variable>

And then reference the path along the lines of this...

<xsl:variable name="type"><xsl:value-of select="name($xpath)" /></xsl:variable>

...or...

<xsl:variable name="type"><xsl:value-of select="$xpath/@attribute" /></xsl:variable>

Of course, thats not going to work as I need to define the XPath within the xpath variable using the select attribute. Any suggestions?


Reply With Quote
  #2 (permalink)  
Old November 17th, 2004, 07:29 AM
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

Without extensions you can't use dynamic paths. If one of the expressions will always return a null node set then you can use the union operator:
Code:
<xsl:variable name=xpath" select="(expression1 | expression2)[1]"/>
Or if one has priority if both are not null then put that first.



--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old November 17th, 2004, 07:44 AM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for that. It seems to work like a dream. So, the expression that I place first will have priority over the other?

I am now using...

<xsl:variable name="xpath" select="($structure/structure/group/*[@id = name(current())]|$structure/structure/*[@id = name(current())])[1]" />

Reply With Quote
  #4 (permalink)  
Old November 17th, 2004, 08:36 AM
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

Well you are creating a union of both selects. If one is null then it won't be included. You are then picking the first node in the set. This assumes each XPath returns at most one node at its root.

--

Joe (Microsoft MVP - XML)
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 Param with XPath expressions V4mp1r3 XSLT 7 June 1st, 2007 11:47 AM
String xsl:param as XPath expression Vx XSLT 4 September 5th, 2006 10:18 AM
chapter4 xsl and xpath problem clinfix BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 August 8th, 2006 02:21 PM
xsl:choose djmarquette XSLT 5 March 29th, 2005 11:44 AM
<xsl:choose> and <xsl:otherwise> problem djmarquette XSLT 4 January 21st, 2005 01:56 PM



All times are GMT -4. The time now is 05:53 PM.


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