Connecting Tech Pros Worldwide Forums | Help | Site Map

XML XPath problem

Tjerk Wolterink
Guest
 
Posts: n/a
#1: Jul 20 '05
Hello i've an xpath problem using sablatron in php.

In xsl i have the following code:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:page="http://www.wolterinkwebdesign.com/xml/page"
xmlns:menu="http://www.wolterinkwebdesign.com/xml/menu"
xmlns:r="http://www.wolterinkwebdesign.com/xml/roles">

<xsl:param name="absolute_url"/>
<xsl:param name="upload_url"/>
<xsl:param name="document_root"/>
<xsl:param name="role"/>
<xsl:param name="xcd_dir"/>

<xsl:variable name="menu" select="document(concat($document_root,
'/menu.xml'))"/>
<xsl:variable name="roles" select="document(concat('file://', $xcd_dir,
'/roles.xml'))"/>

[cut]
<xsl:copy-of
select="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name='all']/r:action[@name='edit']/@grant"/>


Well this xpath expression:
$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name='all']/r:action[@name='edit']/@grant
With these variables:

$role="admin"
$roles:
Using this role file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<roles xmlns="http://www.wolterinkwebdesign.com/xml/roles">

<!--
! The admin role.
! And admin should have all permisions to do its task
!
!-->
<role id="admin" isadmin="true">
<name>Administrator</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>Bezoeker</name>
<description>Bezoeker van de site</description>
<grants>
<for name="all">
<action name="read" grant="true" />
<action name="edit" grant="true" />
</for>
<for name="gastenboek">
<action name="new" grant="true"/>
<action name="edit" grant="true" />
</for>
<for name="medewerkers">
<action name="new" grant="true"/>
</for>
<for name="files">
<action name="new" grant="true"/>
</for>
<for name="news">
<action name="new" grant="true"/>
</for>
</grants>
</role>

</roles>


Gives the following error using sablatron in php:


array(4) {
[0]=>
resource(134) of type (XSLT Processor)
[1]=>
int(3)
[2]=>
int(0)
[3]=>
array(6) {
["msgtype"]=>
string(5) "error"
["code"]=>
string(2) "55"
["module"]=>
string(9) "Sablotron"
["URI"]=>
string(33) "file://C:/webserver/xcd/roles.xml"
["line"]=>
string(2) "44"
["msg"]=>
string(54) "attribute 'grant' created after a child has been added"
}
}


But what am i doing wrong??
Please help me

Joris Gillis
Guest
 
Posts: n/a
#2: Jul 20 '05

re: XML XPath problem


> <xsl:copy-of select="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name='all']/r:action[@name='edit']/@grant"/>[color=blue]
> This xpath expression:
> $roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name='all']/r:action[@name='edit']/@grant
>
>
> Gives the following error: "attribute 'grant' created after a child has been added"[/color]

The problem, here is not the Xpath, but rather the 'xsl:copy'
<xsl:copy-of select="@foo"/>
attempts to add the 'foo' attribute to the result tree. This only works when 'xsl:copy' is encapsulated with an element. e.g.
<parent>
<xsl:copy-of select="@foo"/>
</parent>

And it must be done before any child node is added to this element of the result tree.
Thus:
<parent>
<xsl:copy-of select="@foo"/>
<child/>
</parent>
will work, while
<parent>
<child/>
<xsl:copy-of select="@foo"/>
</parent>
will not.

I hope you can solve the problem now.
regards,

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Tjerk Wolterink
Guest
 
Posts: n/a
#3: Jul 20 '05

re: XML XPath problem


Joris Gillis wrote:[color=blue][color=green]
>> <xsl:copy-of
>> select="$roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name='all']/r:action[@name='edit']/@grant"/>
>>
>> This xpath expression:
>> $roles/r:roles/r:role[@id=$role]/r:grants/r:for[@name='all']/r:action[@name='edit']/@grant
>>
>>
>>
>> Gives the following error: "attribute 'grant' created after a child
>> has been added"[/color]
>
>
> The problem, here is not the Xpath, but rather the 'xsl:copy'
> <xsl:copy-of select="@foo"/>
> attempts to add the 'foo' attribute to the result tree. This only works
> when 'xsl:copy' is encapsulated with an element. e.g.
> <parent>
> <xsl:copy-of select="@foo"/>
> </parent>
>
> And it must be done before any child node is added to this element of
> the result tree.
> Thus:
> <parent>
> <xsl:copy-of select="@foo"/>
> <child/>
> </parent>
> will work, while
> <parent>
> <child/>
> <xsl:copy-of select="@foo"/>
> </parent>
> will not.
>
> I hope you can solve the problem now.
> regards,
>[/color]


damn , stupid me.

but that was not the real problem, it was sort of debugging output. But
now i can debug!
Closed Thread