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 April 21st, 2006, 10:14 AM
Authorized User
 
Join Date: Apr 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default XPath help

Given the next XML file, I need to generate the output shown by the edge tag. The number in the antecedent attribute refers to the id in the itemset tag.

<PMML>
<AssociationModel>
<Item id=”1” value=”wine”/>
<Item id=”2” value=”fish”/>
<Item id=”3” value=”beer”/>

<Itemset id=”5” numberOfItems=”2”>
    <ItemRef itemRef=”2”/>
<ItemRef itemRef=”3”/>
</Itemset>
<Itemset id=”6” numberOfItems=”1”>
    <ItemRef itemRef=”1”/>
</Itemset>

<AssociationRule id=”12” antecedent=”6” consequent=”5”/>
</AssociationModel>
</PMML>


<edge id=”12” source=”1” target=”2,3”> (correct)
<edge id=”12” source=”6” target=”5”> (incorrect)

Is it possible to navigate in the XML document with XPath expressions made in the "mirror template" and return the value in itemref and copy it in the antecedent attribute of association rule? Or exist another way or syntax? Thanks for your help.

<xsl:template match=”Itemset”>
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match=”itemref”>
    <xsl:value-of select=”@itemRef”/>
</xsl:template>

<xsl:template match=”rule”>
    <xsl:call-template name=”mirror”>
        <xsl:with-param name=”data”>
            <xsl:value-of select=”@antecedent”/>
        </xsl:with-param>
    </xsl:call-template>
    <xsl:element name=”edge”>
        <xsl:attribute name=”id”>
            <!-- get value from mirror -- >
                </xsl:attribute>
        </xsl:element>
</xsl:template>

<xsl:template match=”mirror”>
    <xsl:param name=”data”>
    <!-- more instructions -- >
</xsl:template>


 
Old April 21st, 2006, 10:24 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The best way to do this sort of thing is with keys. For example if you define the key

<xsl:key name="ItemKey" match="Item" use="@id"/>

then the function call

key('ItemKey', @itemRef)

will find the Item with id=2 when the context node is the first ItemRef in your data sample.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 21st, 2006, 10:49 AM
Authorized User
 
Join Date: Apr 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael, I'll try it in that way.






Similar Threads
Thread Thread Starter Forum Replies Last Post
XPATH pallone XSLT 4 March 3rd, 2008 10:58 AM
Xpath help please rishid XML 1 February 28th, 2007 03:23 AM
XPATH pallone XSLT 4 November 19th, 2006 07:50 PM
Xpath Ma7T XSLT 2 August 16th, 2005 07:54 AM
XPath rupen XML 2 April 19th, 2005 09:43 AM





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