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 January 18th, 2007, 08:18 PM
Authorized User
 
Join Date: Nov 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using key() and <xsl:key>

Hi all!

I'm trying to use the key() function together with <xsl:key> element in the following way: I have the input document:
################################################## ##################
          <A>
             <B>
                <C1 atr1="_10">
                   <D1>name1</D1>
                </C1>
             </B>
          </A>
          ............
          <A>
             <B>
                <C2>
                    <D2>name</D2>
                    <E2>
                       <F2 atr2="_10"/>
                    </E2>
                </C2>
             </B>
          </A>
################################################## ###################

So when I process this document, when I reach <C2>, I need to insert the "name" value that corresponds to the key "_10" from "atr2", which is the one from "atr1" of tag "C1"; so that would be the name from <D1>.

I tried with:
<xsl:key name="id_to_name" match="A/B/C1" use="@atr1"/>
and call it like this:
<xsl:template match="B/C2">
   <myTag>
      <xsl:value-of select="key('id_to_name', @atr2)/D1"/>
   </myTag>
</xsl:template>

but I get no results.

If anybody can help me it would be great.

Best regards,
Fred
 
Old January 18th, 2007, 08:39 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The C2 element does not have at attribute called @atr2. You need key(..., E2/F2/@atr2)



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 18th, 2007, 08:55 PM
Authorized User
 
Join Date: Nov 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you again Mr. Kay for your help!

Best regards,
Fred





Similar Threads
Thread Thread Starter Forum Replies Last Post
Global variable restrictions in the <xsl:key> iceandrews XSLT 2 August 25th, 2008 01:16 PM
<xsl:key elayaraja.s XSLT 1 July 23rd, 2008 05:00 AM
<bean:message key="PNR.INPUT"/> key has null value warsha_14 Struts 1 November 13th, 2006 07:26 AM
<xsl:for-each> and key() - help needed muchofrio XSLT 5 April 13th, 2006 09:28 AM
<xsl:key> prints extra string? di98svpa XSLT 6 February 6th, 2006 12:13 PM





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