Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 Display Modes
  #1 (permalink)  
Old March 12th, 2004, 08:30 AM
Registered User
 
Join Date: Nov 2003
Location: , , Italy.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default select="node1", select="node2"...

I've got (XML):
Code:
<root>
   <node1> bla bla </node1>
   <node2> bla bla </node1>
   <node3> bla bla </node1>
   <node4> bla bla </node1>
   <node5> bla bla </node1>
</root>
I've got (XSLT):
Code:
<xsl:call-template name="FOO">
   <xsl:with-param name="number" select="1"/>
</xsl:call-template>
and the template:
Code:
<xsl:template name="FOO">
   <xsl:param name="number"/>
   <xsl:copy-of select="concat(node,$number)"/>
</xsl:template>
I wanna copy-of node1, node2, node3
but the concat(node,$number) is not the right way
(Can not convert #STRING to a NodeList!)

is there a solution?

xslt learner :)
Reply With Quote
  #2 (permalink)  
Old March 12th, 2004, 08:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

I don't know of any way to dynamically create selection paths.††If you had written your xml like this instead:
Code:
<root>
†††<node num="1"> bla bla </node>
†††<node num="2"> bla bla </node>
†††<node num="3"> bla bla </node>
†††<node num="4"> bla bla </node>
†††<node num="5"> bla bla </node>
</root>
then you could just use
Code:
<xsl:copy-of select="node[@num=$number]"/>
Reply With Quote
  #3 (permalink)  
Old March 12th, 2004, 08:54 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Try:
Code:
<xsl:template name="FOO">
   <xsl:param name="number"/>
   <xsl:copy-of select="/root/*[name() = concat('node', $number)]"/>
</xsl:template>
or
Code:
<xsl:template name="FOO">
   <xsl:param name="number"/>
   <xsl:copy-of select="//*[name() = concat('node', $number)]"/>
</xsl:template>
if you don't the exact position of the nodes to find. If yur source document has namespaces you will need to change name() to local-name() or alter the XPath to include the namespace.


Joe (MVP - xml)
Reply With Quote
  #4 (permalink)  
Old March 12th, 2004, 09:39 AM
Registered User
 
Join Date: Nov 2003
Location: , , Italy.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by pgtips
 I don't know of any way to dynamically create selection paths. If you had written your xml like this instead:
tnx, but source XML was like I wrote (and it's a problem since it's not the classic <node id="3"/>

xslt learner :)
Reply With Quote
  #5 (permalink)  
Old March 12th, 2004, 09:49 AM
Registered User
 
Join Date: Nov 2003
Location: , , Italy.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by joefawcett
 Try:
Code:
<xsl:template name="FOO">
   <xsl:param name="number"/>
   <xsl:copy-of select="/root/*[name() = concat('node', $number)]"/>
</xsl:template>
GREAT. it worked!
what is the "*" ?

(try to find it in my wrox manual)

xslt learner :)
Reply With Quote
  #6 (permalink)  
Old March 12th, 2004, 09:50 AM
Registered User
 
Join Date: Nov 2003
Location: , , Italy.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

page 394 :)
NameTest

xslt learner :)
Reply With Quote
  #7 (permalink)  
Old March 12th, 2004, 10:33 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Quote:
quote:GREAT. it worked!
what is the "*" ?
It is short for all nodes of the current type on the child axis, in this case the type is element so it's short for all child elements.

Joe (MVP - xml)
Reply With Quote
  #8 (permalink)  
Old March 12th, 2004, 10:38 AM
Registered User
 
Join Date: Nov 2003
Location: , , Italy.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by joefawcett
 
Quote:
quote:GREAT. it worked!
Quote:
what is the "*" ?
It is short for all nodes of the current type on the child axis, in this case the type is element so it's short for all child elements.
I'm so sorry. I already knew "*". It's an important "element" of xslt. :)


xslt learner :)
Reply With Quote
Reply


Thread Tools
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
Select row in GridView WITHOUT using Select button rao965 ASP.NET 2.0 Professional 1 February 15th, 2008 10:44 AM
SELECT from SELECT query? seananderson Access 1 October 12th, 2007 01:40 AM
Select from another select statement to a repeater simsen ASP.NET 2.0 Professional 0 May 2nd, 2007 05:34 PM
Fill select box and select recordset value markd Classic ASP Databases 1 February 20th, 2006 06:41 PM
Select Within A Select Problem vinyl-junkie Classic ASP Databases 6 June 7th, 2003 05:31 PM



All times are GMT -4. The time now is 10:38 AM.


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