 |
| 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
|
|
|
|

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

July 10th, 2006, 07:45 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

July 10th, 2006, 08:05 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

July 10th, 2006, 08:21 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

July 10th, 2006, 08:28 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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 <your_name>\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.
|
|

July 10th, 2006, 08:33 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Oh i tried to print the value of $grab, it displays all the <call> tags, but $grab/call displays nothing.
|
|

July 10th, 2006, 08:38 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok, i found the trick : group="....[name=$grab/*[name()='call']]"
|
|

July 10th, 2006, 08:51 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

July 10th, 2006, 08:58 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

July 10th, 2006, 09:55 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|
 |