Solved

XSLT- Trying to negate a String() function

Posted on 2010-11-08
7
613 Views
Last Modified: 2013-11-18
I have attached some XSLT code, the code is fairly repetitive in that a a template i have replaced with the comment   <!--DO STUFF1() --> is called in two places.

I think I could improve the code by using a negating my NOT condition, but I cant seem to make it work properly.

I want to try and say <xsl:when test="
string(substring-after(substring-after($path, '\'), '\')) ">  OR'ed with <xsl:when test="string(substring-after($path, '\')) ">


And help would be greatly received.

Even if its a complete restructure of the code.

Thanks



<xsl:choose>

		<xsl:when test="starts-with($path,'\')"> <!-- Starts with \ - e.g \abc\def\ghi -->

			<xsl:choose>

				<xsl:when test="not (string(substring-after(substring-after($path, '\'), '\'))) ">

					<!--DO STUFF1() -->

				</xsl:when>

				<xsl:otherwise>

					<xsl:call-template name="xxx">

						<xsl:with-param name="$path" select="substring-after(substring-after($path, '\'), '\')"/>

					</xsl:call-template>

				</xsl:otherwise>

			</xsl:choose>

		</xsl:when>

		<xsl:otherwise> <!-- Doesn't start with \ - e.g abc\def\ghi-->

			<xsl:choose>

				<xsl:when test="not (string(substring-after($path, '\'))) ">

					<!--DO STUFF1() -->

				</xsl:when>

				<xsl:otherwise>

					<xsl:call-template name="xxx">

						<xsl:with-param name="$path" select="substring-after($path, '\')"/>

					</xsl:call-template>

				</xsl:otherwise>

			</xsl:choose>

		</xsl:otherwise>

	</xsl:choose>

Open in new window

0
Comment
Question by:Molko
  • 4
  • 3
7 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 34088012
I think it would greatly simplify your stylesheet if you created a path2 variable first that had the leading "\" stripped off
        <xsl:variable name="path2">

            <xsl:choose>

                <xsl:when test="starts-with($path,'\')"> <!-- Starts with \ - e.g \abc\def\ghi -->

                    <xsl:value-of select="substring($path, 2)"/>

                </xsl:when>

                <xsl:otherwise> <!-- Doesn't start with \ - e.g abc\def\ghi-->

                    <xsl:value-of select="$path"/>

                </xsl:otherwise>

            </xsl:choose>

        </xsl:variable>

        <xsl:choose>

            <xsl:when test="not (string(substring-after($path2, '\'))) ">

                <!--DO STUFF1() -->

            </xsl:when>

            <xsl:otherwise>

                <xsl:call-template name="xxx">

                    <xsl:with-param name="$path" select="substring-after($path2, '\')"/>

                </xsl:call-template>

            </xsl:otherwise>

        </xsl:choose>

Open in new window

0
 

Author Comment

by:Molko
ID: 34090820
I'll take a look at that. The 'path' can be like :

c:\window\temp or

\server\temp

hence the conditional processing
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34090839
I realized that would be the case,
I saw that once you are sure that the possible leading "\" is gone, the processing is exactly the same
you process the bit after the first "\" if it is there, not counting the leading one
so you could first drop that
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:Molko
ID: 34090892
Yes that quite correct, I also call that function recursively, so that i can iterate over the whole path. So i guess that means i will be assigning a value to $path2 every time - I suppose i can move the variable outside the function call ?

0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34093220
yes, move it outside the function call
0
 

Author Closing Comment

by:Molko
ID: 34130020
Thanks
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34130066
welcome
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML namaspace 2 44
Stupid git question 2 63
How to programmatically remove CustomUI ribbon XML customisations from MSOffice files using VBA? 9 98
XSLT XML 4 14
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

867 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