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 June 7th, 2006, 09:23 AM
Authorized User
 
Join Date: Jun 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to use xsl:element tag???

Hi,

I have the following XML:

<sm>
<Allocations>
<Item Parent="C" Level="1" class_code="C" class="Cash (C)" Allocation="0.5" />
<Item Parent="C" Level="2" class_code="00CC" class="Cash (00CC)" Allocation="0.5" />
<Item Parent="C" Level="3" class_code="CC00" class="Cash (CC00)" Allocation="0.5" />
<Item Parent="CE" Level="1" class_code="CE" class="Equity (CE)" Allocation="0.5" />
<Item Parent="CE" Level="2" class_code="00CE" class="Equity (00CE)" Allocation="0.5" />
<Item Parent="CE" Level="3" class_code="CE00" class="Equity (CE00)" Allocation="0.5" />
</Allocations>
</sm>

I have the following XSL:

    <xsl:template match="/">
        <xsl:call-template name="GetMax">
            <xsl:with-param name="Items" select="//Allocations//Item" />
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="GetMax">
        <xsl:param name="Items" />
        <xsl:variable name="MaxLevel">
            <xsl:for-each select="$Items">
                <xsl:sort select="@Level" data-type="number" order="descending" />
                <xsl:if test="position()=1">
                    <xsl:element name="Parent">
                        <xsl:value-of select="@Parent"/>
                    </xsl:element>
                    <xsl:element name="Level">
                        <xsl:value-of select="@Level"/>
                    </xsl:element>
                </xsl:if>
            </xsl:for-each>
        </xsl:variable>
        <xsl:value-of select="$MaxLevel/Parent" />
    </xsl:template>

In the above xsl, I am sorting the xml by Level and then creating a node using the xsl:element tag and putting this into the variable MaxLevel. But I am having trouble retrieving the values by perticular Element. If I use <xsl:value-of select="$MaxLevel" /> instead of <xsl:value-of select="$MaxLevel/Parent" /> at the end, it just prints the value's CE3. I don't want this. I want to be able to select these values 'Parent' and 'Level' Seperately into another variable and print that instead. Could someone guide me on how to archieve this please. Thank you.

NewToXSL

 
Old June 8th, 2006, 05:53 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you are using XSLT 1.0, then your variable named MaxLevel is a "result tree fragment" and you can't reference its content directly with a path expression, unfortunately. Your code would work in XSLT 2.0. In 1.0, many vendors have introduced an extension function of the form xx:node-set() where xx represents a vendor-defined namespace. This then allows you to say select="xx:node-set($MaxLevel)/Parent".

You didn't actually say how your code was failing so I may have the wrong end of the stick.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 8th, 2006, 05:54 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Try substring-before(concat(validSplit,','),',')

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
How to find no.of childnodes of a tag element? sachin635 .NET Framework 3.5 0 September 15th, 2008 04:32 AM
XSL(T) problems with xsl:element pan69 XSLT 3 December 13th, 2007 06:24 AM
Using Variable for xsl:element Name Belch XSLT 5 November 2nd, 2007 04:28 AM
Sorting element in xsl Sakubar Sathik XSLT 5 April 6th, 2006 04:23 AM
xsl variable in xsl tag? di98svpa XSLT 1 February 10th, 2006 01:41 PM





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