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 February 15th, 2005, 07:27 AM
Authorized User
 
Join Date: Jun 2003
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Kabe
Default selection within xsl:key

hi

have this:
<xsl:key name="translateLabel" match="PAGE/CONTENT/DB/RECORDS[@label = 'translatelabels']/RECORD/translation" use="../id"/>

used as: key('translateLabel',id)

possible to write selection in <xsl:key> when there's no result found with the value of 'id', the value of 'id' itself is displayed ?

Now, I'm writing each key() wihtin a <xsl:choose>.
Want to replace this by placing the selection already in <xsl:key>

Kabe
 
Old February 16th, 2005, 07:54 AM
Authorized User
 
Join Date: Jul 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think you need to give a clearer explanation of your problem.

It is worth including snippets of your xml and xslt and the expected output.

Regards
Bryan

 
Old February 25th, 2005, 04:15 AM
Authorized User
 
Join Date: Jun 2003
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Kabe
Default

I defined this key:
<xsl:key name="translateLabel" match="PAGE/CONTENT/DB/RECORDS[@label = 'translatelabels']/RECORD/translation" use="../id"/>

and applying like this:
<xsl:choose>
<xsl:when test="key('translateLabel','overviewtechnical') != ''"><xsl:value-of select="key('translateLabel','overviewtechnical')"/></xsl:when>
<xsl:otherwise>{overviewtechnical}</xsl:otherwise>
</xsl:choose>

My question is if it is possible to move the selection to the xsl:key itself, so I have only to use <xsl:value-of select="key('translateLabel','overviewtechnical')"/> and getting the same result
 
Old February 25th, 2005, 05:06 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sure, just add the predicate [.!=''] to the end of your match pattern in xsl:key.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 25th, 2005, 05:49 AM
Authorized User
 
Join Date: Jun 2003
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Kabe
Default

Isn't this just a part of the solution? In case more options are available

now, u're just moving [.!=''] to xsl:key, but, when there's no value, the result remains empty, while I want to have the value of input back when there's no result (<xsl:otherwise> in my example here above).

... but i'm afraid this isn't possible

thx





Similar Threads
Thread Thread Starter Forum Replies Last Post
Use of xsl:key problem in xslt 2 monadear XSLT 1 September 2nd, 2008 05:13 AM
<xsl:key elayaraja.s XSLT 1 July 23rd, 2008 05:00 AM
using 3 XPaths to index using xsl:key Chamkaur XSLT 3 March 2nd, 2007 04:09 AM
Using key() and <xsl:key> freddy XSLT 2 January 18th, 2007 08:55 PM
xsl:key doesnt work cristtiah XSLT 11 May 24th, 2006 09:57 AM





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