[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: referring to variables using variables?

Subject: RE: referring to variables using variables?
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Tue, 13 Jan 2004 13:35:40 -0000
index variables using xslt
> Thanks very much for your help so far, just wanted to make 
> absolutely sure i 
> understand the select statement in the for-each element  
> select="xx:node-set($index)/*", does it mean that every 
> variable in index is 
> a node and if so why do you have to do that?

A variable created using 

<xsl:variable>
  content
</xsl:variable>

is called (in XSLT 1.0) a "result tree fragment". It is actually a
document root node, but with restrictions that stop you processing it in
the same way as you can process other documents. The xx:node-set()
extension, which is available in most XSLT 1.0 processors under one
namespace or another, converts this restricted document node into a
node-set containing an ordinary document root node, which therefore
allows you to poke around inside the content of the document using path
expressions. Such as xx:node-set($index)/*, for example, which selects
the element children of this document root node.

Michael Kay


> Are there any good web pages where i could find out more 
> about advanced xslt 
> functions which would help me to understand setting up 
> variables in this 
> way? Whenever i come across a problem i tend not to know 
> where to look for 
> solutions so i always end up asking on here as i have a 
> limited experience, 
> does anyone know any really good sites or books that might 
> help me? cheers james walker
> 
> 
> >From: "Michael Kay" <mhk@xxxxxxxxx>
> >Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> >To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> >Subject: RE:  referring to variables using variables?
> >Date: Mon, 12 Jan 2004 20:20:29 -0000
> >
> >I would suggest:
> >
> ><xsl:variable name="index">
> >   <foobar>http:......</foobar>
> >   <jaka>http:....</jaka>
> ></xsl:variable>
> >
> ><xsl:variable name="nsindex" select="xx:node-set($index)/*"/>
> >
> ><xsl:template match="category">
> >   <xsl:variable name="catname" select="name" />
> >
> >   <xsl:for-each 
> >select="document($nsindex/*[name()=$catname])/root/child::*)">
> >
> >Michael Kay
> >
> >
> >
> > > -----Original Message-----
> > > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of james 
> > > walker
> > > Sent: 12 January 2004 16:15
> > > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > > Subject: RE:  referring to variables using variables?
> > >
> > >
> > >
> > > Is there anyway that i can achieve the same solution but in a 
> > > slightly different way?
> > >
> > > thanks james walker
> > >
> > >
> > > >From: "Michael Kay" <mhk@xxxxxxxxx>
> > > >Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > > >To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> > > >Subject: RE:  referring to variables using variables?
> > > >Date: Mon, 12 Jan 2004 15:51:08 -0000
> > > >
> > > >XSLT is not a macro language. The content of a variable 
> is a value 
> > > >(either a boolean, a string, a number, or a node-set). It is
> > > not part
> > > >of the text of an XPath expression. I think this is where your 
> > > >confusion comes from.
> > > >
> > > >For example, if $x contains the string 'xyz', then $x/pqr
> > > does not mean
> > > >xyz/pqr, it means 'xyz'/pqr, which is an error: the operands
> > > of the "/"
> > > >operator must be node-sets, not strings.
> > > >
> > > >Michael Kay
> > > >
> > > > > -----Original Message-----
> > > > > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > > > > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> > > > > james walker
> > > > > Sent: 12 January 2004 13:56
> > > > > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > > > > Subject:  referring to variables using variables?
> > > > >
> > > > >
> > > > > I am trying to access different xml documents where 
> the variable 
> > > > > name of the document (declared at the top of the file) is
> > > equal to
> > > > > the category name of
> > > > > the file being translated:
> > > > > e.g. given this xslt:
> > > > >
> > > > > <xsl:stylesheet version="1.0" 
> > > > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> > > > > <xsl:variable name="jaka" select="document('http:......')" /> 
> > > > > <xsl:variable name="foobar" 
> select="document('http:......')" />
> > > > >
> > > > > <xsl:template match="category">
> > > > > <xsl:variable name="catname" select="name" /> <xsl:for-each 
> > > > > select="$catname/root/child::*)"> <li><xsl:value-of 
> > > > > select="detail" /></li> </xsl:for-each> <xsl:apply-templates 
> > > > > select="./category" /> </xsl:template> </xsl:stylesheet>
> > > > >
> > > > > I translated this with file1.xml which contained the two 
> > > > > category names jaka aand foobar. i have named the 
> categories in
> > > the file1.xml
> > > > > to be $foobar and
> > > > > $jaka so when $catname is substitued into
> > > > > $catname/root/child::* it should
> > > > > look like $foobar/root/child::* for foobar categoyr and
> > > > > $jaka/root/child::*
> > > > > for jaka category.
> > > > >
> > > > > However, when i translate it, it doesnt seem to show
> > > anything when
> > > > > it gets to the xpath staement $catname/root/child::*.
> > > > > I tested to see if it works when u put the variable name 
> > > > > directly in there and it does (e.g. putting  
> > > > > $foobar/root/child::* )?? Does anyone know if i am 
> close to the 
> > > > > solution (am i making a silly mistake
> > > > > with variable decalration?0
> > > > > cheers
> > > > > james walker
> > > > >
> > > > > 
> ________________________________________________________________
> > > > > _
> > > > > Express yourself with cool emoticons - download MSN
> > > Messenger today!
> > > > > http://www.msn.co.uk/messenger
> > > > >
> > > > >
> > > > >  XSL-List info and archive: 
> > > > > http://www.mulberrytech.com/xsl/xsl-list
> > > > >
> > > >
> > > >
> > > >  XSL-List info and archive:
> > > http://www.mulberrytech.com/xsl/xsl-list
> > > >
> > >
> > >
> > > _________________________________________________________________
> > > Find a cheaper internet access deal - choose one to suit you. 
> > > http://www.msn.co.uk/internetaccess
> > >
> > >
> > >  XSL-List info and archive:  
> > > http://www.mulberrytech.com/xsl/xsl-list
> > >
> >
> >
> >  XSL-List info and archive:  
> http://www.mulberrytech.com/xsl/xsl-list
> >
> 
> 
> _________________________________________________________________
> It's fast, it's easy and it's free. Get MSN Messenger today! 
> http://www.msn.co.uk/messenger
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.