Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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.
Reply With Quote
  #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
Reply With Quote
  #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.
Reply With Quote
  #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
Reply With Quote
  #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 :)

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:32 AM.


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