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 July 10th, 2006, 07:05 AM
Authorized User
 
Join Date: Jun 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default match in a set of nodes

Hi everbody,

i'm trying to match something among a list of items. Typically, i have

Code:
  <xsl:variable name="catch">
    <call>foo1</call>
    <call>printf</call>
  </xsl:variable>
and i want to di something like :
Code:
<xsl:for-each-group select="*" group-ending-with="function_name=$grab/call">
i'd like the '=' to test for each <call> if it matches. Is this can be achieved by some way ?

Thanks

 
Old July 10th, 2006, 07:45 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I don't know what function_name and $grab are, so it's a bit hard to see what you're getting at.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 10th, 2006, 08:05 AM
Authorized User
 
Join Date: Jun 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

oh sorry, i changed the names to be more clear.
$grab is $catch
function_name is just a node name
select all node that have the node function_name listed in the $catch variable

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

It sounds as if you want

group-ending-with="*[name()=$catch/call]"

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 10th, 2006, 08:28 AM
Authorized User
 
Join Date: Jun 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

doesn't seem to work.
i ahe the original xml file :
Code:
  <expr_stmt>
    <expr>
      <call>
        <name>printf</name>
        <argument_list>(
        <argument>
          <expr>"Usage : helloworld &lt;your_name&gt;\n"</expr>
        </argument>)</argument_list>
      </call>
    </expr>;</expr_stmt>
and the transformation :

Code:
<xsl:for-each-group select="*" group-ending-with="if|expr_stmt[child::expr/call[name=$grab/call]]">
doesn't produce the expected result which is : group expressions (expr_stmt) by making the printf function (for example) and the if statements as delimiters

if works if i say [name='printf'] but not [name=$grab/call]. i think it is due to the fact that $grab has many <call> tags.

 
Old July 10th, 2006, 08:33 AM
Authorized User
 
Join Date: Jun 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh i tried to print the value of $grab, it displays all the <call> tags, but $grab/call displays nothing.

 
Old July 10th, 2006, 08:38 AM
Authorized User
 
Join Date: Jun 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, i found the trick : group="....[name=$grab/*[name()='call']]"


 
Old July 10th, 2006, 08:51 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your code looks OK to me. Please post a complete sample source document and stylesheet showing the output you are getting and the output you expect.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 10th, 2006, 08:58 AM
Authorized User
 
Join Date: Jun 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the code is a litte long. but to demonstrate that the previous code doesn't work, take this :

Code:
 <xsl:variable name="grab">
    <call>foo1</call>
    <call>printf</call>
  </xsl:variable>
and

[code]
<xsl:value-of select="$grab/call>
-> nothing

<xsl:value-of select="$grab/*[name()='call']>
-> foo1 print
[code]

thanks

 
Old July 10th, 2006, 09:55 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

That suggests you've probably got namespace problems. I asked for complete code so I could help you, but you're leaving me guessing.

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
Appending set of elements after the similar nodes sesath XSLT 2 May 15th, 2007 10:16 AM
template match doesnt match the required node Tomi XSLT 2 March 12th, 2007 06:24 AM
Match by attribute. ole_v2 XSLT 6 November 11th, 2006 10:24 AM
Match records bram_code VB Databases Basics 1 May 5th, 2006 10:36 AM
match containing variable csbdeady XML 1 October 25th, 2004 05:57 AM





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