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(_at_)mhk(_dot_)me(_dot_)uk>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject: RE: [xsl] 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(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf
Of james
walker
Sent: 12 January 2004 16:15
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] 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(_at_)mhk(_dot_)me(_dot_)uk>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject: RE: [xsl] 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(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On
Behalf Of
james walker
Sent: 12 January 2004 13:56
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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