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 March 12th, 2004, 08:30 AM
Registered User
 
Join Date: Nov 2003
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 :)
 
Old March 12th, 2004, 08:48 AM
Friend of Wrox
 
Join Date: Jun 2003
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]"/>
 
Old March 12th, 2004, 08:54 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)
 
Old March 12th, 2004, 09:39 AM
Registered User
 
Join Date: Nov 2003
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 :)
 
Old March 12th, 2004, 09:49 AM
Registered User
 
Join Date: Nov 2003
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 :)
 
Old March 12th, 2004, 09:50 AM
Registered User
 
Join Date: Nov 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

page 394 :)
NameTest

xslt learner :)
 
Old March 12th, 2004, 10:33 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)
 
Old March 12th, 2004, 10:38 AM
Registered User
 
Join Date: Nov 2003
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 :)





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 12:40 AM
Select from another select statement to a repeater simsen ASP.NET 2.0 Professional 0 May 2nd, 2007 04: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 04:31 PM





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