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, 2006, 09:21 PM
Authorized User
 
Join Date: Nov 2006
Posts: 28
Thanks: 0
Thanked 1 Time in 1 Post
Default Choosing first or second element

Hi

I have in my xsl file something like this:
<tag1 atr1="{A/B/@atr}"
      atr2="{A/B/@atr}">
</tag1>
Now {A/B/@atr} returns 2 values and I want the first to be assigned to atr1 and the second to atr2. For the way it is now (described above) I get:
<tag1 atr1="val1 val2"
         atr2="val1 val2">
</tag1>
Instead I want:
<tag1 atr1="val1"
         atr2="val2">
</tag1>
So how should I change the xsl file to achieve this? I use Saxon 8 and XSLT 2.0. Thank you.

Michael
 
Old November 8th, 2006, 04:38 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Note that there's actually a difference here between 1.0 and 2.0 - in 1.0 you'll always get the first value, in 2.0 you get all the values space separated.

To choose a specific value, write atr1="{(A/B/@atr)[1]}" or atr2="{(A/B/@atr)[2]}".

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 8th, 2006, 09:13 AM
Authorized User
 
Join Date: Nov 2006
Posts: 28
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thank you for your reply. I tried something similar to your solution, mainly ...="{A/B/@atr}[1]", thinking that what comes out from the {A/B/@atr} is kind of an array of values and I only need to choose the first one. Of course it did not work, so I thought that the solution would not be that easy, so I tried various schemes, like using para[1], or the last() function, or different other functions or combinations. I obviously lack some basic knowledge, but XSLT is starting to grow on me.

Michael
 
Old November 8th, 2006, 09:26 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In an attribute value template the curly braces enclose an XPath expression. Anything outside the curlies is literal text to be copied to the result document.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 8th, 2006, 09:31 AM
Authorized User
 
Join Date: Nov 2006
Posts: 28
Thanks: 0
Thanked 1 Time in 1 Post
Default

I understand now, thank you for the information.

Michael





Similar Threads
Thread Thread Starter Forum Replies Last Post
I need help choosing the right book. lJohnl BOOK: Beginning JavaScript 3rd Ed. ISBN: 978-0-470-05151-1 2 September 6th, 2007 08:03 AM
Choosing your ajax framework hazemtorab Ajax 1 July 18th, 2006 06:48 PM
choosing from drop down list noor ASP.NET 1.0 and 1.1 Basics 2 July 1st, 2005 05:57 AM
choosing directories joconnor PHP How-To 0 August 11th, 2004 09:12 AM
Choosing a database rbmese Visual C++ 3 August 9th, 2004 08:19 AM





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