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 February 28th, 2006, 05:04 AM
Registered User
 
Join Date: Feb 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default constructing node-set content to xsl:variable

Hi,

I would be very glad if anyone could explain this to me.

Given this xml data
<a>
  <b>blablabla</b>
</a>

and this stylesheet

<xsl:template match="/"/>
  <xsl:variable name="a">
    <xsl:copy-of select="/a"/>
  </xsl:variable>

  <xsl:value-of select="exsl:node-set($a)/b"/>
</xsl:template>

I am aiming to get the output "blablabla" but currently i get nothing.
If I hardcode the variable data like this it works:

..
  <xsl:variable name="a">
    <b>blablabla</b>
  </xsl:variable>
..

I have also tried with xslt 2.0 and skipping the exsl function but i get the same result. Can anyone please explain this. Is copy-of the correct function to use at all here?

Thanks
-Thomas


 
Old February 28th, 2006, 05:16 AM
Registered User
 
Join Date: Feb 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try it once
<xsl:template match="a">
  <p>
   <xsl:value-of select="b"/>
  </p>
</xsl:template>
Quote:
quote:Originally posted by MrWay
 Hi,

I would be very glad if anyone could explain this to me.

Given this xml data
<a>
<b>blablabla</b>
</a>

and this stylesheet

<xsl:template match="/"/>
<xsl:variable name="a">
    <xsl:copy-of select="/a"/>
</xsl:variable>

<xsl:value-of select="exsl:node-set($a)/b"/>
</xsl:template>

I am aiming to get the output "blablabla" but currently i get nothing.
If I hardcode the variable data like this it works:

..
<xsl:variable name="a">
    <b>blablabla</b>
</xsl:variable>
..

I have also tried with xslt 2.0 and skipping the exsl function but i get the same result. Can anyone please explain this. Is copy-of the correct function to use at all here?

Thanks
-Thomas


 
Old February 28th, 2006, 05:54 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The value of $a is a document node whose only child is an a element. To find the b element, you need exslt:node-set($a)/a/b

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 28th, 2006, 10:39 AM
Registered User
 
Join Date: Feb 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael, it works beautifully.






Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath: set operation with a disjoint node set rich_unger XSLT 7 May 6th, 2008 09:24 AM
The reference node is not a child of this node.XSL XMLUser XSLT 2 February 25th, 2008 05:22 AM
xsl using variable on a node Debiprasad XSLT 1 June 22nd, 2006 12:20 PM
Problem using xsl:for-each on a exsl:node-set ballo XSLT 11 March 28th, 2006 10:47 AM
Retrieve the escaped node content carlos.bravo XSLT 4 September 16th, 2005 03:23 PM





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