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 July 18th, 2010, 04:12 AM
Authorized User
 
Join Date: Jul 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default the XSL variable into other variable

I have the problem with the XSL variable...the XSL variable into other variable...

my source:

1) (here OK!)

<xsl:variable name="pathId" select="Orders/Order[ORD_Num='0607V45621014F']"/> (global var)

<xsl:value-of select="$pathId/Receiver/REC_Name"/>


2) (here not OK!)

...create the global var;

<xsl:variable name="id">

<idNum>0607V45621014F</idNum>

</xsl:variable>


...insert in other var...


<xsl:variable name="pathId" select="Orders/Order[ORD_Num='$id/idNum']"/> (..with ' or " or null but not ok)

..in the end...but, not OK!

<xsl:value-of select="$pathId/Receiver/REC_Name"/>


other example...using the document() function...


3) (here not OK!)



...create the global var;

<xsl:variable name="XmlFile" select="YG.xml"/>

insert here...

<xsl:value-of select="document('$XmlFile')/aziende/azienda/ragione_sociale"/> (..with ' or " or null but not ok)



4) (here OK!)

<xsl:value-of select="document('YG.xml')/aziende/azienda/ragione_sociale"/>



Help me!

Thanks!

Giambattista
 
Old July 18th, 2010, 08:53 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Your post is a little confusing, but I will give it a shot:

This line:
Code:
<xsl:variable name="XmlFile" select="YG.xml"/>
should be:

Code:
<xsl:variable name="XmlFile" select="'YG.xml'"/>
The select statement is looking for an xpath expression or a string. Either wrap you string in single quotes

Code:
'YG.xml'
or

Code:
string('YG.xml')
also,

Code:
<xsl:value-of select="document('$XmlFile')/aziende/azienda/ragione_sociale"/>
should be

Code:
<xsl:value-of select="document($XmlFile)/aziende/azienda/ragione_sociale"/>
When calling a variable, you do not use single quote, because it is not a string.

Last edited by bonekrusher; July 18th, 2010 at 08:56 AM..
 
Old July 18th, 2010, 02:24 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In this expression:

$pathId/Receiver/REC_Name

$pathId is not in quotes, and it refers to a variable whose value is a node-set. So that's fine.

In this expression:

Orders/Order[ORD_Num='$id/idNum']

$id/idnum is within quotes, so it's just a character string. If you removed the quotes, it would be OK in XSLT 2.0, but not in 1.0, because the variable $id is a result-tree-fragment rather than a node-set.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old July 21st, 2010, 03:22 AM
Authorized User
 
Join Date: Jul 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you.....

My solution is:

<xsl:variable name="XmlFile" select="'YG.xml'"/>
<xsl:variable name="id" select="'0607V45621014F'"/>
<xsl:variable name="azienda" select="'azienda'"/>

"'name'" not "name" and not 'name'


<xsl:variable name="pathId" select="Orders/Order[ORD_Num=$id]"/>

<xsl:value-of select="document($XmlFile)/aziende/*[name()=$azienda]/ragione_sociale"/>





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to assign one variable value to another xsl variable in xsl Anil_Base XSLT 3 March 24th, 2009 01:17 PM
Set xsl variable using Javascript variable Kunn XSLT 5 December 31st, 2008 02:43 AM
ASSIGNING A JAVA SCRIPT VARIABLE TO A XSL VARIABLE SOMANATHAN10 XSLT 1 February 21st, 2007 04:26 AM
xsl:variable holding name of an xsl:param perissos XSLT 0 December 5th, 2006 07:09 AM
pass java variable to xsl variable kathy1016cats XSLT 1 June 14th, 2006 06:23 PM





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