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 February 2nd, 2009, 06:51 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default Finding if an attribute has a specific value

I'm using Saxon 9b

I have an XML file produced by a separate application. The structure was defined by someone besides me and I cannot change it.

I have a root node that has 0 or more 'payload-block' elements somewhere inside it. Each payload-block has an attribute ('@block) that takes on a value from 1 to 5. The child element is of type name-def-param and it also has an attribute (@name) that takes on a string name (letters, number)

What I want to do if find if there are any specific name-def-param elements with a specified @name value.

So.. I tried this:
Code:
    <xsl:template match="name-def-param" mode="doNew">
        <xsl:param name="inputMsg1"/>
        <xsl:param name="block"/>

        <xsl:variable name="name" select="upper-case(@name)"/>
        <xsl:variable name="posi" select="@posi"/>
            <xsl:if
                test="empty($inputMsg1//payload-block[@block-id='$block']/name-def-param[upper-case(@name) = $name])">

                <xsl:text>&#x0a;</xsl:text>
                <xsl:text>Named Block: </xsl:text>
                <xsl:value-of select="$block"></xsl:value-of>
                <xsl:text>&#x0a;</xsl:text>

                <xsl:text>New Attribute: </xsl:text>
                <xsl:value-of select="$name"/>
                <xsl:text>&#x0a;</xsl:text>
            </xsl:if>
    </xsl:template>
If the target values is not in the source tree, then it's marked as a 'New' item.

The problem is I'm getting false hits. Even if the value is present in the target, this is still telling me it cannot find it.

Am I misunderstanding how empty() works?

I've also tried counting the instances with count($inputMsg1//payload-block[@block-id='$block']/name-def-param[upper-case(@name) = $name]) = 0 in the test. And it's no better.
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
 
Old February 2nd, 2009, 06:57 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

No.. I don't understand how attribute comparisons work.. apparently..

The single quotes around the [@block-id = '$block'] statement were throwing everything off. Removing the quotes seems to have fixed it.

Thanks!
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare





Similar Threads
Thread Thread Starter Forum Replies Last Post
finding a unique attribute Navy1991_1 XSLT 1 July 6th, 2008 06:07 PM
sort on specific attribute kgoldvas XSLT 2 July 17th, 2007 09:42 AM
Finding specific string martinrhague Access 7 November 2nd, 2006 12:54 PM
datagrids question -- finding a specific row bazookajoe76 C# 1 January 22nd, 2005 12:08 PM
Finding a specific character within a string tp194 Classic ASP Databases 2 October 12th, 2003 10:41 PM





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