473,657 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

strange xml xpath xsl error:

I've xml code like this:

roles.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<roles xmlns="http://www.wolterinkwe bdesign.com/xml/roles">

<!--
! The admin role.
! And admin should have all permisions to do its task
!
!-->
<role id="admin" isadmin="true">
<name>Administr ator</name>
<description> De Administrator kan alles verwijderen, toevoegen en bewerken op de site.</description>
<grants>
<for name="all">
<action name="edit" grant="true" />
<action name="new" grant="true" />
<action name="read" grant="true" />
</for>
</grants>
</role>

<!--
! A generic visitor role.
! Anybody who is not given a role explicit is a visitor
!-->
<role id="visitor" isvisitor="true ">
<name>Bezoeke r</name>
<description>Be zoeker van de site</description>
a
<grants>
b
<for name="all">
<action name="read" grant="true" />
<action name="edit" grant="true" />
</for>
<for name="gastenboe k">
<action name="new" grant="true"/>
<action name="edit" grant="true" />
</for>
<for name="medewerke rs">
<action name="new" grant="true"/>
</for>
<for name="files">
y
<action name="new" grant="true">d</action>
</for>
<for name="news">
<action name="new" grant="true"/>
</for>
</grants>
</role>

</roles>
XSL code like this:
ps, $roles is always the above roles.xml
<!--
This template below works on for example
<page:button-edit-delete module="files" id="3"/>
-->
<xsl:template match="page:but ton-edit-delete">
<xsl:if test="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name=./@module]/r:action[@name='edit']/@grant='true' or $roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name='all']/r:action[@name='edit']/@grant='true'">
<[cut]
</xsl:if>
</xsl:template>

<!--
This template below does NOT work on for example
<page:button-new module="files" id="3"/>
-->
<xsl:template match="page:but ton-new">
<!-- debug code -->
BUTTON NEW MATCHED!
<xsl:value-of select="./@module"/>
<xsl:copy-of select="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name=./@module]"/>
<xsl:copy-of select="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name='files']"/>
<!-- end debug code -->

<xsl:if test="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name=./@module]/r:action[@name='new']/@grant='true' or $roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name='all']/r:action[@name='new']/@grant='true'">
[cut]
</xsl:if>
</xsl:template>
Strange enough:
this works: <xsl:value-of select="./@module"/> output:files
this does not work:
<xsl:copy-of select="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name=./@module]"/> output= ""
and this does work:
<xsl:copy-of select="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name='files']"/>

I do not understend the if test in the second template is almost the same as in the first template, but the first template always works and
the second not..... i cannot find the error
Jul 20 '05 #1
4 1544
[cut]

i've had the following solution:

<!--
! Matches a new button
!-->
<xsl:template match="page:but ton-new">
<xsl:variable name="module" select="./@module"/>
<xsl:if test="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name=$module]/r:action[@name='new']/@grant='true' or $roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name='all']/r:action[@name='new']/@grant='true'">
<div class="new_butt on">
<form enctype="multip art/form-data" action="$php_se lf" method="post">
<input type="hidden" name="module" value="{@module }" />
<input type="hidden" name="name" value="{@multip le}" />
<input type="hidden" name="new_reque st" value="true" />
<input class="new_butt on" type="submit" value="Nieuw item toevoegen" />
</form>
</div>
</xsl:if>
</xsl:template>

But that is ugly!! I think it must be possible without the xsl:variable
Jul 20 '05 #2
>
Strange enough:
this works: <xsl:value-of select="./@module"/> output:files
this does not work:
<xsl:copy-of select="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name=./@module]"/> output= ""
and this does work:
<xsl:copy-of select="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name='files']"/>

I do not understand the if test in the second template is almost the same as in the first template, but the first template always works and
the second not..... i cannot find the error


Hi,
you could use this:
<xsl:copy-of select="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name=current()/@module]"/>

Explanation:

In this Xpath expression:
<xsl:value-of select="./@module"/>
the period (.) selects the context node, which - in this case- is equal to the current node-set of the template.

But between the [brackets] in:
<xsl:copy-of select="/r:for[@name=./@module]"/>
, the context node is changed to the node preceding the left bracket ('r:for'). So this expression is trying to access the 'module' attribute of 'r:for'. In other words, you cannot access the current node-set with '.' when you're between brackets. You have to use 'current()' in stead.

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #3
Joris Gillis wrote:

Strange enough:
this works: <xsl:value-of select="./@module"/> output:files
this does not work:
<xsl:copy-of
select="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name=./@module]"/>
output= ""
and this does work:
<xsl:copy-of
select="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name='files']"/>

I do not understand the if test in the second template is almost the
same as in the first template, but the first template always works and
the second not..... i cannot find the error


Hi,
you could use this:
<xsl:copy-of
select="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name=current()/@module]"/>
Explanation:

In this Xpath expression:
<xsl:value-of select="./@module"/>
the period (.) selects the context node, which - in this case- is equal
to the current node-set of the template.

But between the [brackets] in:
<xsl:copy-of select="/r:for[@name=./@module]"/>
, the context node is changed to the node preceding the left bracket
('r:for'). So this expression is trying to access the 'module' attribute
of 'r:for'. In other words, you cannot access the current node-set with
'.' when you're between brackets. You have to use 'current()' in stead.

regards,


i thought of that, but i did not know current() existed.
But then how do you explain that this template works:

<xsl:template match="page:but ton-edit-delete">
<xsl:if test="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name=./@module]/r:action[@name='edit']/@grant='true' or $roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name='all']/r:action[@name='edit']/@grant='true'">
[cut]
</xsl:if>
</xsl:template>
And this one not:

<xsl:template match="page:but ton-new">
<xsl:if test="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name=./@module]/r:action[@name='new']/@grant='true' or $roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name='all']/r:action[@name='new']/@grant='true'">
[cut]
</xsl:if>
</xsl:template>
I do not understand that. the only differences ar in @name='edit' or @name='new' and in the match attribute of xsl:template.
Maybe i should give more detail?
Jul 20 '05 #4
> i thought of that, but i did not know current() existed.
But then how do you explain that this template works:

<xsl:template match="page:but ton-edit-delete">
<xsl:if test="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name=./@module]/r:action[@name='edit']/@grant='true' or $roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name='all']/r:action[@name='edit']/@grant='true'">
[cut]
</xsl:if>
</xsl:template>
And this one not:

<xsl:template match="page:but ton-new">
<xsl:if test="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name=./@module]/r:action[@name='new']/@grant='true' or $roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name='all']/r:action[@name='new']/@grant='true'" [cut]
</xsl:if>
</xsl:template>
I do not understand that. the only differences ar in @name='edit' or @name='new' and in the match attribute of xsl:template.

I'm not really sure either. One guess is that there's an 'action' node in your XML that does not have a 'name' attribute. That node would match the XPath expression because its non-existing 'name' attribute woulkd its non-existing 'module' attribute.

btw, I think it would be better to use a shorter notation like this:
<xsl:if test="//r:roles/r:role[@id=$role]/r:grants/r:for[@name='all' or @name=current()/@module]/r:action[@name='new']/@grant='true'">

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #5

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

Similar topics

1
6817
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for elements, attributes, ".", and "..", plus also the "" predicate format is supported - however, only one predicate per path step is supported, and expr must be a relative path. 2. Poor performance
0
1919
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
2
2968
by: kj | last post by:
Suppose I have some XML document that contains tags of the form <... xmlns:foo="http://www.bar.org/foo"> <... xmlns:foo="baz"> <... xmlns:frobozz="http://www.bar.org/foo"> What's the XPath expression to select the namespace nodes with prefix "foo"? And what's the XPath expression to select the
4
4955
by: Rune | last post by:
I have two queries that appear to be exactly the same, but one of them returns null while the other one returns a valid result! Can anyone provide an explanation to why this is so? Below is an nunit test that exposes the problem. I have run the test under both the 1.0 and 1.1 framework with the same result. public void XPathBooks() { XmlDocument smallDoc = new XmlDocument();
5
4203
by: laks | last post by:
Hi I have the following xsl stmt. <xsl:for-each select="JOB_POSTINGS/JOB_POSTING \"> <xsl:sort select="JOB_TITLE" order="ascending"/> This works fine when I use it. But when using multiple values in the where clause as below
5
7925
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
2
2752
by: Weston | last post by:
Poking around with XPath using SimpleXML, it looks like there are at least a few reasonably common XPath operators and predicates that aren't supported. I'd like to check my observations against other people's experience, and find out if I'm missing something. Here's what it looks like to me in PHP 5.2.0: * the count() predicate seems to fail quietly (no error or warning, you just receive a false value from the xpath method rather than...
1
8513
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
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
7352
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
6176
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
5642
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
4173
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
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
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
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.