473,421 Members | 1,631 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,421 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 2116
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...
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.