 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 22nd, 2011, 08:24 PM
|
|
Registered User
|
|
Join Date: Jan 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
LDAP multi-group memberships select one membership
I am new to XSLT Please help
The group priority level
lowest(Public-1) TO Highest (PRIVATE-3)
Public-1 Public-2 Public-3 CONFID-1 CONFID-2 CONFID-3 PRIVATE-1 PRIVATE-2 PRIVATE-3
For example a user LDAP query gives a file
<result>
<DN>CN=Test User ID Priv-2,CN=Users,DC=Lab,DC=acme,DC=com</DN>
<attribute-value name="memberOf">CN=CONFID-2,OU=Groups,DC=Lab,DC=acme,DC=com</attribute-value>
<attribute-value name="memberOf">CN=PRIVATE-2,OU=Groups,DC=Lab,DC=acme,DC=com</attribute-value>
<attribute-value name="memberOf">CN=Public-3,OU=Groups,DC=Lab,DC=acme,DC=com</attribute-value>
</result>
The xslt should select the highest priority level available for the user and output it
In the file above the user has membership in groups
CONFID-2, PRIVATE-2, Public-3
the xslt should give the output just
CN=PRIVATE-2,OU=Groups,DC=Lab,DC=acme,DC=com
|
|

January 22nd, 2011, 08:42 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
You haven't said whether you're using XSLT 2.0 (which makes this kind of problem much easier), and you haven't said which part of the problem you are stuck on - is it parsing the syntax of the attribute-value, or is it doing the sorting? So short of giving you a complete working stylesheet, it's not clear where I should start in giving advice.
My advice would be
(a) Make sure you are using XSLT 2.0
(b) Start by parsing the attribute value (such as <attribute-value name="memberOf">CN=CONFID-2,OU=Groups,DC=Lab,DC=acme,DC=com</attribute-value>) into an XML structure - you can do this using xsl:analyze-string
(c) Write a function that translates the values Public-1, Public-2 etc into a numeric scale
(d) Sort on the result of this function
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

January 22nd, 2011, 08:52 PM
|
|
Registered User
|
|
Join Date: Jan 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank You Mr. Kay for the quick reply. I am really thrilled to get a response from you. I have your book right here with me. I am following it. This for an implementation in DataPower. So I cannot use 2.0. I am very new to XSLT and a snippet of code if possible will be really helpful. I am stuck at the logic of how to go about the sorting part and select the highest priority group. Thank you in advance
Last edited by click_Apply; January 22nd, 2011 at 08:55 PM..
|
|

January 23rd, 2011, 02:46 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Well, if the structure of the attribute values is as regular as in your example, then you can extract the CN values using simple substring-before() and substring-after() calls, so that part is quite possible in XSLT 1.0. Doing a sort on a computed sort key is a bit more tricky. The usual solution is to use two passes - first create a temporary tree on which the computed sort key is present as an explicit attribute; then do the sort on this tree. If you want to do this in a single transformation, it needs the xx:node-set() extension. Alternatively there's a David Carlisle style hack - if you remove the first five characters of the CN value you get C-1, C-2, C-3, D-1, D-2, D-3, TE-1, TE-2, TE-3, which just happens to sort in the desired order. I'm afraid this kind of hackery tends to crop up when you're stuck with using XSLT 1.0.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

January 24th, 2011, 03:10 PM
|
|
Registered User
|
|
Join Date: Jan 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank You Mr. Kay. The issue is resolved according to your suggestions.
|
|
 |