473,396 Members | 2,102 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,396 software developers and data experts.

xsl:variable

Hello

I try to tranform a XML Document in php/Sablotron with the following XSL
Stylesheet.
I tried to write "@id='1'" with the variable chapter_id.

So it works:
<xsl:variable name="chapter_id">1</xsl:variable>
<xsl:template match="chapter[@id='1']">
snipp..
</xsl:template>

But with
<xsl:template match="chapter[@id='$chapter_id']">
or
<xsl:template match="chapter[@id=$chapter_id]">
it doesn't.
These way
<xsl:template match="chapter[@id='<xsl:value-of select="$chapter_id"/>']">
and
<xsl:template match="chapter[@id=<xsl:value-of select="$chapter_id"/>]">
it doesn't work either.

How i have to write it that it is correct

Thanks for your help
Nagi
Jul 20 '05 #1
5 4096
In article <1f******************************@ID-25423.user.dfncis.de>,
Nagi Peters <na**@gmx.de> wrote:

% So it works:
% <xsl:variable name="chapter_id">1</xsl:variable>
% <xsl:template match="chapter[@id='1']">
% snipp..
% </xsl:template>

% But with
% <xsl:template match="chapter[@id='$chapter_id']">

This will compare @id to the string $chapter_id

% <xsl:template match="chapter[@id=$chapter_id]">

This should work. Could you post a complete, but minimal, example
(data and stylesheet)?
--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #2
Hi Patric
On Wed, 24 Sep 2003 17:15:30 +0200 (MEST), Patrick TJ McPhee wrote:
<xsl:template match="chapter[@id=$chapter_id]">
This should work. Could you post a complete, but minimal, example
(data and stylesheet)?


Here the xml:
<book>
<chapter id="1" label="1">
</chapter>
</book>

And the xsl:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" encoding="ISO-8859-1" />
<xsl:variable name="chapter_id">1</xsl:variable>
<xsl:template match="chapter[@id=$chapter_id]">
<xsl:value-of select="@label"/>
</xsl:template>
</xsl:stylesheet>

Tested on WinXP:
Tested with Sablotron (in php4.3.3).
Errror: match pattern contains a variable reference Code: 23

And Saxon 6.5.3:
Error at xsl:template on line 5 of file:/c:/temp/vartest.xsl:
The match pattern in xsl:template may not contain references to variables
Transformation failed: Failed to compile stylesheet. 1 error detected.

Same with <xsl:template match="chapter[@id='1']"> Works fine in both.

Any idea?

Thanks

Nagi
Jul 20 '05 #3
In article <e7******************************@ID-25423.user.dfncis.de>,
Nagi Peters <na**@gmx.de> wrote:

[...]

% <xsl:template match="chapter[@id=$chapter_id]">

% Tested on WinXP:
% Tested with Sablotron (in php4.3.3).
% Errror: match pattern contains a variable reference Code: 23
%
% And Saxon 6.5.3:
% Error at xsl:template on line 5 of file:/c:/temp/vartest.xsl:
% The match pattern in xsl:template may not contain references to variables
% Transformation failed: Failed to compile stylesheet. 1 error detected.

Obviously there's no way to do this with those processors, then. I'm not
a standards lawyer, but I just quickly looked over the grammar for
patterns and I don't see any reason for disallowing variables in the
predicate. In fact it says `Predicates in a pattern can use arbitrary
expressions just like predicates in a location path.'

libxml does allow this, and your example works. I don't have anything
else installed on this machine so I can't comment beyond that.
--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #4
pt**@interlog.com (Patrick TJ McPhee) writes:
In article <e7******************************@ID-25423.user.dfncis.de>,
Nagi Peters <na**@gmx.de> wrote:

[...]

% <xsl:template match="chapter[@id=$chapter_id]">

% Tested on WinXP:
% Tested with Sablotron (in php4.3.3).
% Errror: match pattern contains a variable reference Code: 23
%
% And Saxon 6.5.3:
% Error at xsl:template on line 5 of file:/c:/temp/vartest.xsl:
% The match pattern in xsl:template may not contain references to variables
% Transformation failed: Failed to compile stylesheet. 1 error detected.

Obviously there's no way to do this with those processors, then. I'm not
a standards lawyer, but I just quickly looked over the grammar for
patterns and I don't see any reason for disallowing variables in the
predicate. In fact it says `Predicates in a pattern can use arbitrary
expressions just like predicates in a location path.'


In §5.3 ("Defining Template Rules"), para 1, it says, "It is an
error for the value of the match attribute to contain a
VariableReference". Guess that explains it.

-Micah
Jul 20 '05 #5
> % <xsl:template match="chapter[@id=$chapter_id]">

libxml does allow this


....then it has a bug that should be reported.

A workaround that doesn't violate any rules:

<xsl:template match="chapter">
<xsl:if test="@id=$chapter_id">
...
</xsl:if>
</xsl:template>
Jul 20 '05 #6

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

Similar topics

1
by: Xeon | last post by:
Hi, I'm trying this code snippet below but the parser (sablotron) returns error : <xsl:choose> <xsl:when test="some test case"> <xsl:variable name="test" select="0"/> </xsl:when>...
4
by: sylvain.loiseau | last post by:
Hello Given a node set, I try to compute the total of the string-length value of each node. For instance, with : <xsl:for-each select="//q"> <!-- the length of each node is compute with:...
2
by: Richard | last post by:
Suppose I create a variable named "var" such as: <xsl:variable name="var">VarValue</xsl:variable> and then I want to insert its value into an attribute <Element attr=" {the value of var} "> so...
10
by: Tjerk Wolterink | last post by:
The following code does not work: <xsl:variable name="width" select="form:image-width"/> <xsl:if test="$width>$max_image_width"> <xsl:variable name="width" select="$max_image_width"/> </xsl:if>...
1
by: schaf | last post by:
Hello NG ! I have a big problem. I would like to go through a xml file in a xsl:for-each statement. for-each entry (ID) in the XML file i would like to call an xsl:function, which returns a...
2
by: sucheta.phatak | last post by:
Hello, I am trying to use XSLT. Here is the problem that I am facing. My XML file: <Book level="1" name="Mapplicationtoc1"> ....... Some more tags </Book>
5
by: Afshar Mohebbi | last post by:
Hi everybody there, I've declared a <xsl:variable name="something" select="999"/> in my xslt and when I want to set another value in it (with same syntax) I get error the variable "something" has...
2
by: jobooker | last post by:
I'm having issues sorting. The short description is, how do I set the select attribute of xsl:sort to be the value of an xsl:variable? The longer description follows: What I want to do is to be...
0
by: Markchivs | last post by:
Hi all, I wonder if anyone can shed any light on this problem for me? In the following code I'm trying to set a variable called 'atts' with a node set of attributes which will include the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...
0
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
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,...

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.