Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| 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 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
  #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')"/>
            </data>
           <xsl:apply-templates/>
   </xsl:element>
</xsl:template>

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


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

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





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

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:

key('itemkey','@itemRef')

and my first instinct is to correct it to:

key('itemkey',@itemRef)

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
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference


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





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