Solved

Help with XSL file - sorting and attributes

Posted on 2011-03-04
8
318 Views
Last Modified: 2013-11-18
I've fiddled with this for some time and can't get the output formatted how I want from this sample .xml file.

<file>
<zid>127</zid>
<path>/</path>
<inheritedRightsFilter value="rwceafms"><read/><write/><create/><erase/><accessControl/><fileScan/><modify/><supervisor/></inheritedRightsFilter>
<trustee><name>.O=ABC.T=ABCTREE.</name><id>52ec6e00-7f3c-11d6-ab-54-0000e26c189c</id><rights value="rf"><read/><fileScan/></rights></trustee>
<trustee><name>.OU=workstations.OU=Perth.O=ABC.T=ABCTREE.</name><id>d2ca2514-f754-43dc-fc-98-1425cad254f7</id><rights value="rwcefm"><read/><write/><create/><erase/><fileScan/><modify/></rights></trustee>
<trustee><name>.CN=admin.O=ABC.T=ABCTREE.</name><id>52ec6e02-7f3c-11d6-ab-54-0000e26c189c</id><rights value="rwceafm"><read/><write/><create/><erase/><accessControl/><fileScan/><modify/></rights></trustee>
</file>

<file>
<zid>129</zid><path>/._NETWARE</path>
<inheritedRightsFilter value="s"><supervisor/></inheritedRightsFilter>
</file>

<file>
<zid>131</zid>
<path>/it</path>
<inheritedRightsFilter value="s"><supervisor/></inheritedRightsFilter>
<trustee><name>.CN=admin.O=ABC.T=ABCTREE.</name><id>52ec6e02-7f3c-11d6-ab-54-0000e26c189c</id><rights value="rwceafm"><read/><write/><create/><erase/><accessControl/><fileScan/><modify/></rights></trustee>
<trustee><name>.CN=adminbak.O=ABC.T=ABCTREE.</name><id>851e2b07-40f5-4a3a-8c-9c-072b1e85f540</id><rights value="rwceafm"><read/><write/><create/><erase/><accessControl/><fileScan/><modify/></rights></trustee>
<trustee><name>.CN=blokeman.OU=Perth.O=ABC.T=ABCTREE.</name><id>95d06080-814b-11d6-ab-56-0000e26c189c</id><rights value="rf"><read/><fileScan/></rights></trustee>
</file>

Open in new window


What I want is to extract a subset of the information as follows:
list sorted by <path>
   <inheritedRightsFilter value> attribute <!-- always just one entry -->
   List sorted by <trustee>
       <name>  <rights value> attribute

The problem I am having is sorting the <path> list and creating the sorted sublist <trustee>, plus extracting the 'value' attribute from <inheritedRightsFilter>.
What is the easiest way to achieve this?
0
Comment
Question by:blokeman
  • 4
  • 4
8 Comments
 
LVL 18

Assisted Solution

by:zc2
zc2 earned 500 total points
ID: 35041506
Can not say I quite understood the desired output format, but may be my sample will give you some ideas...
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes" encoding="iso-8859-1"/>
	<xsl:template match="/root">
	
		<xsl:for-each select="file">
			<xsl:sort select="path" order="ascending"/>
			
			path: <xsl:value-of select="path"/>
			inheritedRightsFilter value attribute: <xsl:value-of select="inheritedRightsFilter/@value"/>

			<xsl:for-each select="trustee">
				<xsl:sort select="name" order="ascending"/>
				trustee: <xsl:value-of select="name"/> 
				rights value attribute: <xsl:value-of select="rights/@value"/>,
			</xsl:for-each>
  		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>

Open in new window

0
 
LVL 18

Expert Comment

by:zc2
ID: 35041515
I forgot to mention, the XML you provided is not well-formed, it does not grow from a single root. I added a node called "root" and referenced it from the XSLT (<xsl:template match="/root">). In your real solution this approach could be different.
0
 

Author Comment

by:blokeman
ID: 35041541
Wow - that was quick!
I'll test your advice now...

Sorry about my original file not being well-formed.  Here is the full file:

<?xml version="1.0" encoding="UFT-8" ?>
<?xml-stylesheet type="text/xsl" href="trustee-apps.xsl"?>
<metadata>
<trusteeInfo>
<file>
<zid>127</zid>
<path>/</path>
<inheritedRightsFilter value="rwceafms"><read/><write/><create/><erase/><accessControl/><fileScan/><modify/><supervisor/></inheritedRightsFilter>
<trustee><name>.O=ABC.T=ABCTREE.</name><id>52ec6e00-7f3c-11d6-ab-54-0000e26c189c</id><rights value="rf"><read/><fileScan/></rights></trustee>
<trustee><name>.OU=workstations.OU=Perth.O=ABC.T=ABCTREE.</name><id>d2ca2514-f754-43dc-fc-98-1425cad254f7</id><rights value="rwcefm"><read/><write/><create/><erase/><fileScan/><modify/></rights></trustee>
<trustee><name>.CN=admin.O=ABC.T=ABCTREE.</name><id>52ec6e02-7f3c-11d6-ab-54-0000e26c189c</id><rights value="rwceafm"><read/><write/><create/><erase/><accessControl/><fileScan/><modify/></rights></trustee>
</file>

<file>
<zid>129</zid><path>/._NETWARE</path>
<inheritedRightsFilter value="s"><supervisor/></inheritedRightsFilter>
</file>

<file>
<zid>131</zid>
<path>/it</path>
<inheritedRightsFilter value="s"><supervisor/></inheritedRightsFilter>
<trustee><name>.CN=admin.O=ABC.T=ABCTREE.</name><id>52ec6e02-7f3c-11d6-ab-54-0000e26c189c</id><rights value="rwceafm"><read/><write/><create/><erase/><accessControl/><fileScan/><modify/></rights></trustee>
<trustee><name>.CN=adminbak.O=ABC.T=ABCTREE.</name><id>851e2b07-40f5-4a3a-8c-9c-072b1e85f540</id><rights value="rwceafm"><read/><write/><create/><erase/><accessControl/><fileScan/><modify/></rights></trustee>
<trustee><name>.CN=blokeman.OU=Perth.O=ABC.T=ABCTREE.</name><id>95d06080-814b-11d6-ab-56-0000e26c189c</id><rights value="rf"><read/><fileScan/></rights></trustee>
</file>
</trusteeInfo>
</metadata>

Open in new window

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:blokeman
ID: 35041618
Very close! :-)
Just needs a bit of tweaking...

After modifying your version slightly, see my line 4, this is the .xsl file I used:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes" encoding="iso-8859-1"/>
	<xsl:template match="/trusteeInfo">
	
		<xsl:for-each select="file">
			<xsl:sort select="path" order="ascending"/>
			
			path: <xsl:value-of select="path"/>
			inheritedRightsFilter value attribute: <xsl:value-of select="inheritedRightsFilter/@value"/>

			<xsl:for-each select="trustee">
				<xsl:sort select="name" order="ascending"/>
				trustee: <xsl:value-of select="name"/> 
				rights value attribute: <xsl:value-of select="rights/@value"/>,
			</xsl:for-each>
  		</xsl:for-each>

	</xsl:template>
</xsl:stylesheet>

Open in new window


and this is the result:


127/

.O=ABC.T=ABCTREE.52ec6e00-7f3c-11d6-ab-54-0000e26c189c
.OU=workstations.OU=Perth.O=ABC.T=ABCTREE.d2ca2514-f754-43dc-fc-98-1425cad254f7
.CN=admin.O=ABC.T=ABCTREE.52ec6e02-7f3c-11d6-ab-54-0000e26c189c


129/._NETWARE


131/it

.CN=admin.O=ABC.T=ABCTREE.52ec6e02-7f3c-11d6-ab-54-0000e26c189c
.CN=adminbak.O=ABC.T=ABCTREE.851e2b07-40f5-4a3a-8c-9c-072b1e85f540
.CN=blokeman.OU=Perth.O=ABC.T=ABCTREE.95d06080-814b-11d6-ab-56-0000e26c189c

Open in new window


The result I am after is, if we use for example the /it folder (the last output section) :
 /it
   inheritedRightsFilter value attribute: s
   trustee: .CN=admin.O=ABC.T=ABCTREE.                        rights value attribute: rwceafm
   trustee: .CN=adminbak.O=ABC.T=ABCTREE.               rights value attribute: rwceafm
   trustee: .CN=blokeman.OU=Perth.O=ABC.T=ABCTREE.  rights value attribute: rf
0
 

Author Comment

by:blokeman
ID: 35041771
Any ideas why this line didn't output?
inheritedRightsFilter value attribute: <xsl:value-of select="inheritedRightsFilter/@value"/>
0
 
LVL 18

Accepted Solution

by:
zc2 earned 500 total points
ID: 35044198
It strange in your output each value is placed on a new line. May be that because you're using different XSLT processor (I use MSXML). But, anyway, this is not important, because it's the totally wrong output.
The matter of fact, the XSLT template I sent you and you have modified is not used at all. That because the output is completely differ from the desired.
And the template is not used, because the XML has two enclosed root nodes (the <metadata> and the       <trusteeInfo> ), but the XSLT has only one (/trusteeInfo) mentioned in the template pattern: <xsl:template match="/trusteeInfo">.

Please try to change the row (the one you modified) to the following:
<xsl:template match="/metadata/trusteeInfo">

0
 

Author Comment

by:blokeman
ID: 35066917
Thanks!
This looks great
	PATH: /
			INHERITED RIGHTS FILTER : rwceafms
				TRUSTEE: .CN=admin.O=ABC.T=ABCTREE. 
				RIGHTS: rwceafm
				TRUSTEE: .O=ABC.T=ABCTREE. 
				RIGHTS: rf
				TRUSTEE: .OU=workstations.OU=Perth.O=ABC.T=ABCTREE. 
				RIGHTS: rwcefm
			
			PATH: /it
			INHERITED RIGHTS FILTER : s
				TRUSTEE: .CN=adminbak.O=ABC.T=ABCTREE. 
				RIGHTS: rwceafm
				TRUSTEE: .CN=admin.O=ABC.T=ABCTREE. 
				RIGHTS: rwceafm
				TRUSTEE: .CN=blokeman.OU=Perth.O=ABC.T=ABCTREE. 
				RIGHTS: rf
			
			PATH: /._NETWARE
			INHERITED RIGHTS FILTER : s

Open in new window


I'll tweak it a bit more to use a two column table rather than the list, for TRUSTEE and RIGHTS.  This should help readability.
0
 
LVL 18

Expert Comment

by:zc2
ID: 35070786
You're welcome!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now