473,802 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_i d">1</xsl:variable>
<xsl:template match="chapter[@id='1']">
snipp..
</xsl:template>

But with
<xsl:template match="chapter[@id='$chapter_i d']">
or
<xsl:template match="chapter[@id=$chapter_id]">
it doesn't.
These way
<xsl:template match="chapter[@id='<xsl:value-of select="$chapte r_id"/>']">
and
<xsl:template match="chapter[@id=<xsl:value-of select="$chapte r_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 4130
In article <1f************ *************** ***@ID-25423.user.dfnc is.de>,
Nagi Peters <na**@gmx.de> wrote:

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

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

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.c om
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:styleshe et 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_i d">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.dfnc is.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.c om
Jul 20 '05 #4
pt**@interlog.c om (Patrick TJ McPhee) writes:
In article <e7************ *************** ***@ID-25423.user.dfnc is.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
VariableReferen ce". 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=$chap ter_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
4417
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> <xsl:otherwise>
4
2589
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: --> <xsl:value-of select="string-length(.)" />
2
31401
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 that it would generate <Element attr=" VarValue "> What syntax do I use to do this? If I specify <Element attr=" <xsl:value-of select='$var'/> "> then the parser complains that &lt; &gt; must be used for
10
3827
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> <img class="admin" width="{$width}" src="{form:image-url}" /> The width attribute of img is always "", the $max_image_width variable is set to 200 and $width is initially set to the width of the image.
1
1611
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 number. This number i have to summarize during the whole for-each statement. At the end i should have the sum of the added numbers. Like:
2
1482
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
6322
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 been declared previously. I couldn't find a way to change it's value. It seems it is constant. Is there any alternative way? Thanks in Advance Afshar
2
2890
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 able to make a data table sortable by different headers. Right now, I've got javascript that lets you click on a column header, and then it changes the DOM of the xsl file (changes the select attribute of the xsl:sort element) and reapplies the...
0
1318
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 attributes @KEY1 and @KEY2. However the first code example only populates the 'atts' variable with the first attribute value @KEY1, when I want both: <xsl:variable name="atts"> <xsl:choose> <xsl:when test="local-name()='DELETE'">
0
10305
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10063
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9115
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.