Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old April 29th, 2008, 03:28 PM
Registered User
 
Join Date: Apr 2008
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default substitute text() node value in XPath expression

I'm using XSLT 2.0,

following is my XSLT,

<xsl:for-each select="ServiceTemplate">
<xsl:apply-templates select="//ServiceRequestTemplate[@TemplateSet=text()]">
</xsl:apply-templates>
</xsl:for-each>

I want to select nodes from the XML based on the the value of text() but the above transformation doesn't seem to work. Please help.

Thanks.
  #2 (permalink)  
Old April 29th, 2008, 09:06 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I can't really tell what you are trying to do so I can't correct your code but perhaps I can explain why it is obviously wrong. The expression

select="//ServiceRequestTemplate[@TemplateSet=text()]"

would only select elements like this:

<ServiceRequestTemplate TemplateSet="ABCDE">ABCDE</ServiceRequestTemplate>

that is elements whose content is equal to the value of their TemplateSet attribute. That would seem an unusual thing to want to do.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
  #3 (permalink)  
Old April 29th, 2008, 10:02 PM
Registered User
 
Join Date: Apr 2008
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry for the confusion, Here is my XML

<sm:Publish>
<sm:ServiceRequestTemplateSet>
<ServiceRequestTemplate>#f8M0KKVxWJiAhL2E</ServiceRequestTemplate>
</sm:ServiceRequestTemplateSet>

<sm:ServiceRequestTemplate TemplateSet="#f8M0KKVxWJiAhL2E">
</sm:ServiceRequestTemplate>
</smPublish>
This is my XSLT :

<xsl:template match="sm:ServiceRequestTemplateSet">
<xsl:for-each select="ServiceRequestTemplate">
<xsl:apply-templates select="//sm:ServiceRequestTemplate[@TemplateSet=text()]"/>
</xsl:for-each>
</xsl:template>

so for a <sm:ServiceRequestTemplateSet>, I want to get the text() value of each <ServiceRequestTemplate> and select <sm:ServiceRequestTemplate> node which has attribute TemplateSet=text().

I'm not sure if i'm on the right track. I would appreciate your help. Thanks.
  #4 (permalink)  
Old April 30th, 2008, 01:57 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

When you use text() within the predicate, it refers to the text() of the sm:ServiceRequestTemplate element that is the subject of the predicate, not the text() of the original ServiceRequestTemplate (confusing choice of names!)

Use current()/text(), or just current() (because the string value of the element is the same as the value of its text node).

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
  #5 (permalink)  
Old April 30th, 2008, 08:39 AM
Registered User
 
Join Date: Apr 2008
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for taking the time Michael, that was very helpful :)



Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath 2.0 every expression stolte XSLT 5 November 24th, 2008 03:32 PM
XPath to get next node (sibling) jeft0nes XSLT 2 August 8th, 2007 08:30 PM
XPath Expression NEO1976 XSLT 11 August 2nd, 2006 02:28 AM
Need help with XPATH Expression benomathew XSLT 1 May 12th, 2006 04:41 AM
Need help with XPATH Expression benomathew XML 1 May 9th, 2006 03:38 PM





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