[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XML access control by custom ID

Subject: Re: XML access control by custom ID
From: Jacobus Reyneke <jacobusreyneke@xxxxxxxxx>
Date: Tue, 16 Mar 2010 10:09:46 +0200
Re:  XML access control by custom ID
Thanks a great deal Micheal.

No response required on this post. It's just for information:
Honestly, I have not been able to get your solution to work. It copies
the input file "as is". The solution provided by AC does the trick,
but it would be interesting to see your solution at work also. I tried
fixing ;-) your solution, but I've never worked with keys before, so I
will come back to it, once I have keys under the belt.


---------Test input file:---------
Access controlled content (data.xml):
<?xml version="1.0" encoding="UTF-8"?>
<root>
<a some_attributes="xyz" my_id="1">
   123
</a>
<b attribute="xxx" my_id="2">
   ABC
</b>
</root>

----------User role access control settings (access.xml)---------
<?xml version="1.0" encoding="UTF-8"?>
<userroles>
   <administrator>
      <read>
         <my_id>1</my_id>
         <my_id>2</my_id>
      </read>
      <write>
         <my_id>1</my_id>
         <my_id>2</my_id>
      </write>
   </administrator>
   <anybody>
      <read>
         <my_id>1</my_id>
      </read>
      <write>
         <my_id>2</my_id>
      </write>
   </anybody>
</userroles>


-----------Your stylesheet:--------
<xsl:stylesheet version="2.0"
 xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 <xsl:param name="username" as="xs:string" select="'anybody'" />

 <xsl:variable name="acl-doc" as="document-node()"
 select="doc( 'access.xml' )"/>

 <xsl:variable name="accessible" as="xs:string*"
 select="$acl-doc/*/*[local-name() = $username]/*/my_id"/>

 <!-- LKP: make up key by concatenating username, separator, id -->
 <xsl:key name="right-for-id" match="my_id"
 use="concat( ../../local-name(), '--', . )"/>

 <xsl:template match="users/*"/><!-- ignore by default -->

 <!-- process accessible nodes: copy and add @access -->
 <xsl:template match="users/*[ @my_id = $accessible ]" priority="1">
 <xsl:copy>
  <xsl:copy-of select="@*"/>
  <!-- LKP: as above -->
  <xsl:variable name="lkp-key"
   select="concat( $username, '--', @my_id )"/>
  <xsl:attribute name="access"
   select="key( 'right-for-id', $lkp-key, $acl-doc )/../local-name()"/>
  <xsl:apply-templates/>
 </xsl:copy>
 </xsl:template>

 <xsl:template match="@*|node()">
 <xsl:copy>
  <xsl:apply-templates select="@*|node()"/>
 </xsl:copy>
 </xsl:template>

</xsl:stylesheet>

------------Expected results:-------------
<?xml version="1.0" encoding="UTF-8"?>
<a access="read" some_attributes="xyz" my_id="1">
   123
</a>
<b access="write" attribute="xxx" my_id="2">
   ABC
</b>

-------Actual results:---------
A copy of data.xml "as is"

Unfortunately I don't understand your solution (yet) so it's difficult to debug.

Kind regards,
Jacobus

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.