?
Solved

XSLT - Processing a directory path (Windows and unix)

Posted on 2009-04-26
3
Medium Priority
?
252 Views
Last Modified: 2013-11-18
Hi

I have a template that processes a directory path such as C:\Windows\Temp\MyTemp

I want to be able to process a UNIX path such as /home/etc/temp

Attached is the template.

My problem is that I have no easy way of detecting the root directory. In Windows, its pretty simple becuase i can use the ':' Anything before the ':' is the root.

I am looking for suggestion on how can do this for unix. Becuase my template calls itselft i never know which / is the root one. I am not sure how to detect the 1st /

Ideally I want to keep the same style of template.

Thanks

<xsl:template name="process-path">
	<xsl:param name="path"/>
	
	<xsl:choose>
		<xsl:when test="contains($path),'\'"></xsl:when>
			<Item>
					<xsl:choose>
						<xsl:when test="contains(substring-before($path,'\'),':')">
							<name>root</name>	
							<itemname><xsl:value-of select="substring-before($path,'\')"/>\</itemname>
							<xsl:call-template name="process-path">
								<xsl:with-param name="path" select="substring-after($path,'\')"></xsl:with-param>
							</xsl:call-template>
						</xsl:when>
						<xsl:otherwise>
							<name>dir</name>	
							<itemname><xsl:value-of select="substring-before($path,'\')"/>\</itemname>
							<xsl:call-template name="process-path">
								<xsl:with-param name="path" select="substring-after($path,'\')"></xsl:with-param>
							</xsl:call-template>
						</xsl:otherwise>
					</xsl:choose>
			</Item>	
	
	</xsl:choose>
</xsl:template>

Open in new window

0
Comment
Question by:Molko
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 24235347
my first idea was to also pass the original path as a parameter and check a starts-with condition of the found sub path with the original path... that is still something you could do if you don't like the following

What you call a root for the unix path, is always prepended with a "/"
so, the condition is simple, the sub-path that has a "/" in front of it is the root...
is that logic correct?
   <xsl:template name="process-unix-path">
        <xsl:param name="path"/>
         <xsl:choose>
            <xsl:when test="contains($path,'/')">
            <Item>
                <xsl:choose>
                    <xsl:when test="starts-with($path,'/')">
                        <xsl:variable name="r-path" select="substring-after($path, '/')"></xsl:variable>
                        <name>root</name>	
                        <itemname><xsl:value-of select="concat('/', substring-before($r-path,'/'))"/>/</itemname>
                        <xsl:call-template name="process-unix-path">
                            <xsl:with-param name="path" select="substring-after($r-path,'/')"></xsl:with-param>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:otherwise>
                        <name>dir</name>	
                        <itemname><xsl:value-of select="substring-before($path,'/')"/>/</itemname>
                        <xsl:call-template name="process-unix-path">
                            <xsl:with-param name="path" select="substring-after($path,'/')"></xsl:with-param>
                         </xsl:call-template>
                    </xsl:otherwise>
                </xsl:choose>
            </Item>	
            </xsl:when>   
        </xsl:choose>
    </xsl:template>

Open in new window

0
 

Author Closing Comment

by:Molko
ID: 31574636
thanks...did the trick
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24285748
welcome
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

840 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