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 26th, 2006, 10:55 AM
Authorized User
 
Join Date: May 2006
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default compare nodetree value with key

I'm a newby and have a problem of searching for a value in a xml node tree with a key, maybe someone can help me with this:
I have a variable $myElement and the value is a nodetree something like this:
<nodetree>
   <xsd:sequence>
      <xsd:element ref="A">
      <xsd:element ref="B">
   </xsd:sequence>
</nodetree>

I have defined a key like this:
<xsl:key name="searchtree" match="xsd:sequence/xsd:element" use="string(@ref)" />

I want to check if variable $myValue is in the tree. For instance with the value "B".
I tried this but I never get any results
  • <xsl:if test="$myElement/key('searchtree',$myValue)"/>
  • <xsl:variable name="myTest" select="$myElement/key('searchtree',$myValue)"/>
What am i doing wrong.:(
 
Old June 26th, 2006, 11:18 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Note that using key() on the rhs of "/" is allowed only in XSLT 2.0.

Apart from that, I can't see anything wrong. Try submitting a complete but small example.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 30th, 2006, 08:19 AM
Authorized User
 
Join Date: May 2006
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Found the problem. It seems that my keyboard has been switched into dutch keyboard settings and the quote was something different. When switching to english keyboard and retype the key value it worked.
And later changed the key like this.


    <xsl:key name="lomchild" match="xsd:schema/xsd:complexType[@name = 'lomType']/xsd:sequence/xsd:element" use="@ref"/>
    ...

    <xsl:variable name="mainPattern" select="key('lomchild',$refNode)"/>

instead of


    <xsl:key name="lomchild" match="xsd:sequence/xsd:element" use="@ref"/>
    ...

    <xsl:variable name="mainPattern" select="xsd:schema/xsd:complexType[@name = 'lomType']/key('lomchild',$refNode)"/>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Foreign key not updating with Primary key xavier1945 BOOK: Access 2003 VBA Programmer's Reference 2 July 4th, 2007 09:48 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
compare these date fields and compare and get the susanring Oracle 1 July 24th, 2006 04:58 PM
FOREIGN KEY and PRIMARY KEY Constraints junemo Oracle 10 June 15th, 2004 01:00 AM





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