Solved

Help with XSL file - sorting and attributes

Posted on 2011-03-04
8
309 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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
CSS (line height?) issue 2 57
Swiper slider stops between pages 11 32
How to read XML file attributes... 17 42
Create XML 5 35
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa‚Ķ
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

744 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

15 Experts available now in Live!

Get 1:1 Help Now