Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
| FAQ | Members List | Calendar | 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
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 24th, 2006, 07:02 AM
Authorized User
Join Date: Apr 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with key function

Hi! The problem is this: Given the xsl code, I want generate the output represented by the <anothernode> tag. The XML input code is represented by the <itemset> tag. I use the key function but I can’t get the value of the itemref tag. My doubt is in the use attribute of the key tag and how the concat function is used with values in the case of the second itemset tag with two itemref tags.

Thanks in advanced!

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:pmml="http://www.dmg.org/PMML-3_0" version="1.0">

<xsl:key name="itemkey" match="pmml:ItemRef" use="parent::pmml:Itemset/@id"/>

<xsl:template match="pmml:Itemset">
   <xsl:element name="anothernode">
     <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
            <data key="name">

                <xsl:value-of select="key('itemkey','@itemRef')"/>

<xsl:template match="pmml:ItemRef">
   <xsl:comment><xsl:value-of select="@itemRef"/></xsl:comment>

<Itemset id="9" numberOfItems="1" support="0.31096912">
<ItemRef itemRef="6"/>
<Itemset id="1" numberOfItems="2" support="0.17784878">
<ItemRef itemRef="1"/>
<ItemRef itemRef="2"/>

<anothernode id=”9”>
    <data key=”name”>6</data>
<anothernode id=”1”>
    <data key=”name”>1,2</data>

Reply With Quote
  #2 (permalink)  
Old April 24th, 2006, 07:30 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts

It might be worth pointing out that you've used the word "tag" 6 times in your question, and each time you actually mean "element". An element has two tags, a start tag and an end tag. So the "second itemset tag" is actually the end tag of the first itemset element. A common mistake.

I'm not actually sure what you're trying to do here. This call is obviously wrong:


and my first instinct is to correct it to:


but that doesn't look right either, because the context node is an Itemset element, and Itemset elements don't have @itemRef attributes. In fact your key definition itself looks rather strange:

<xsl:key name="itemkey" match="pmml:ItemRef" use="parent::pmml:Itemset/@id"/>

Do you really want to index ItemRef elements on the id of their containing Itemset?

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote

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
Using key() and <xsl:key> freddy XSLT 2 January 18th, 2007 08:55 PM
<bean:message key="PNR.INPUT"/> key has null value warsha_14 Struts 1 November 13th, 2006 07:26 AM
TAB KEY working together KEY PRESS event thomaz C# 4 August 20th, 2006 02:47 PM
function key F1 rajanikrishna Javascript 1 January 27th, 2004 05:21 AM
Key function shamsad Oracle 0 October 4th, 2003 06:40 AM

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

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