Solved

Help with XSL file - sorting and attributes

Posted on 2011-03-04
8
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

617 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