473,372 Members | 1,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

Basic XSLT/XSLTC question

I'm using xalan-j_2_6_0 and trying to get an example from Michael
Kay's book to work:

<xsl:template match="/">
<xsl:variable name="rainbow">
<color>red</color>
<color>blue</color>
<color>green</color>
</xsl:variable>

<xsl:for-each select="$rainbow/color">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>

Both XSLTC and XSLT generate errors when they encounter the XPath
expression in the select attribute. I cannot get XSLTC or XSLT to
accept any expression that qualifies a variable in a select statement.

Am I trying to do something that is strictly forbidden here? Am I
misunderstanding what Michael Kay's example was supposed to do?

Any help is greatly appreciated!!

Justine
Jul 20 '05 #1
3 2113
I guess that you read the second edition of Mike's book, in which he covered
XSLT 1.1.

XSLT 1.1 was never developed by the W3C into a final status and is not a
standard. The current standard of XSLT 1.0 has the concept of RTF (Result
Tree Fragment).

An RTF cannot be treated like a node-set in XPath -- any such attempt
results in raising an error -- this is exactly what you described.

In order to process an RTF as a node-set, one must use an
implementation-defined extension function with the usual name of node-set(),
belonging to an implementation-dependent namespace, or use the
common:node-set() function as defined by EXSLT.

These functions take an RTF and convert it to a regular node-set. Then their
result is a regular tree (a node-set having just one root node) and can be
navigated using XPath.
Therefore, you also have to use whatever implementation-defined
xxx:node-set() extension function is available for your XSLT processor.
Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
"Justine Hlista" <jb**************@yahoo.com> wrote in message
news:3e**************************@posting.google.c om...
I'm using xalan-j_2_6_0 and trying to get an example from Michael
Kay's book to work:

<xsl:template match="/">
<xsl:variable name="rainbow">
<color>red</color>
<color>blue</color>
<color>green</color>
</xsl:variable>

<xsl:for-each select="$rainbow/color">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>

Both XSLTC and XSLT generate errors when they encounter the XPath
expression in the select attribute. I cannot get XSLTC or XSLT to
accept any expression that qualifies a variable in a select statement.

Am I trying to do something that is strictly forbidden here? Am I
misunderstanding what Michael Kay's example was supposed to do?

Any help is greatly appreciated!!

Justine

Jul 20 '05 #2
Hi,

It is also possible to store "XML constants" inside your stylesheet and
refer to them with the document() function, that will be adressable with
XPath (no extension required) :

<xsl:stylesheet ...
xmlns:xsl="..."
xmlns:data="...">

<data:structures>
<rainbow>
<color>red</color>
<color>blue</color>
<color>green</color>
</rainbow>
</data:structures>

<xsl:template match="/">
<xsl:variable name="rainbow"
select="document('')/*/data:structures/rainbow"/>
<xsl:for-each select="$rainbow/color">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

Dimitre Novatchev [MVP XML] wrote:
I guess that you read the second edition of Mike's book, in which he covered
XSLT 1.1.

XSLT 1.1 was never developed by the W3C into a final status and is not a
standard. The current standard of XSLT 1.0 has the concept of RTF (Result
Tree Fragment).

An RTF cannot be treated like a node-set in XPath -- any such attempt
results in raising an error -- this is exactly what you described.

In order to process an RTF as a node-set, one must use an
implementation-defined extension function with the usual name of node-set(),
belonging to an implementation-dependent namespace, or use the
common:node-set() function as defined by EXSLT.

These functions take an RTF and convert it to a regular node-set. Then their
result is a regular tree (a node-set having just one root node) and can be
navigated using XPath.
Therefore, you also have to use whatever implementation-defined
xxx:node-set() extension function is available for your XSLT processor.
Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
"Justine Hlista" <jb**************@yahoo.com> wrote in message
news:3e**************************@posting.google.c om...
I'm using xalan-j_2_6_0 and trying to get an example from Michael
Kay's book to work:

<xsl:template match="/">
<xsl:variable name="rainbow">
<color>red</color>
<color>blue</color>
<color>green</color>
</xsl:variable>

<xsl:for-each select="$rainbow/color">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>

Both XSLTC and XSLT generate errors when they encounter the XPath
expression in the select attribute. I cannot get XSLTC or XSLT to
accept any expression that qualifies a variable in a select statement.

Am I trying to do something that is strictly forbidden here? Am I
misunderstanding what Michael Kay's example was supposed to do?

Any help is greatly appreciated!!

Justine


--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
Jul 20 '05 #3

"Philippe Poulard" <Ph****************@SPAMsophia.inria.fr> wrote in message
news:c2**********@news-sop.inria.fr...
Hi,

It is also possible to store "XML constants" inside your stylesheet and
refer to them with the document() function, that will be adressable with
XPath (no extension required) :


Yes, and this is a really valuable technique for creating data structures to
be used by the XSLT application.

The example given by the OP can be solved completely that way.

What cannot be done in this way is to access dynamically created nodes.
Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: LW | last post by:
I'm using the following free implementation of an XSLT "split" function, as a template: http://www.exslt.org/str/functions/split/str.split.template.xsl.html Basically, it allows me to call it...
9
by: Tom | last post by:
Hey all, I've been planning to get myself started with DocBook for quite some time now, so when I unexpectedly encountered a task for which DocBook might actually be very useful, I thought I'd...
4
by: Ringo Langly | last post by:
Hi all, I'm a seasoned web programmer, but I've never touched XSLT. It's always been one of those acronyms I've never needed to educate myself on. Now... we're working with a web content...
0
by: Jordan Willms | last post by:
My xsl stylesheet is as simple as follows: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet xmlns:ims="http://www.imsglobal.org/xsd/imsmd_v1p2"...
0
by: Meikel | last post by:
Just a hint for others: I got a NullPointerException in org.apache.xalan.xsltc.runtime.output.TransletOutputHandlerFactory.getSerializationHandler and wondered what went wrong. I had put the...
0
by: DAnne | last post by:
Hi, I'm very new to xslt and this is my first time posting to a Forum so please forgive me if I transgress any protocols. I have to do a tally report. This report is divided up into sections....
1
by: Sergey Dubinets | last post by:
In effort to prioritize our goals we composed the list of random features each of them may add value to set of XSLT tools offered from Microsoft. 1. XSLTc (Compiler for XSLT...
14
by: Lee | last post by:
I have a xml file, here is sample part: <?xml version="1.0" encoding="UTF-8"?> <ProducsList> <Product id="1"> <SpecList> <Spec> <SpecLabel>Height</SpecLabel> <SpecValue>10</SpecValue>...
2
by: astroboiii | last post by:
New to the whole xml thing and finding w3schools to be an excellent resource. Now down to my question: I have several xml files I need to parse through and grab relevant information from and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.