?
Solved

Efficient XSLT to Render Hyperlink

Posted on 2008-11-02
3
Medium Priority
?
582 Views
Last Modified: 2013-11-18
I have some XSLT which appears to do what I need it to (listed in the source snippet box below). What I want to know, is this the simplest way of doing this?

The XSLT renders the hyperlink URL next to the link text (only when printed).
Visit EE (www.experts-exchange.com)

The URL should only be rendered when:
   - The link text is not a URL itself.
            <hyperlink href="www.experts-exchange.com">www.experts-exchange.com</hyperlink>
   - The link text is blank (because the URL is rendered instead of text).
            <hyperlink href="www.experts-exchange.com"></hyperlink>
   - The URL refers to a page, website, or file. I don't want anything like 'javascript:addTotals' to be rendered!!
            <hyperlink href="javascript:addTotals();">Calculate Totals</hyperlink>
<xsl:template match="hyperlink" mode="content">
	<xsl:variable name="innerText" select="child::node()" />
	<a>
		<xsl:attribute name="href">
			<xsl:choose>
				<xsl:when test="string-length(@href)>0">
					<xsl:value-of select="@href" />
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>#</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:attribute>
		<xsl:choose>
			<xsl:when test="string-length($innerText)>0">
				<xsl:call-template name="render-html-content" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="@href" />
			</xsl:otherwise>
		</xsl:choose>
	</a>
	<xsl:if test="string-length($innerText)>0 and not(contains($innerText,'www.') or contains($innerText,'tp://') or starts-with(@url,'javascript:'))">
		<span class="PrintOnly">
			<xsl:text> (</xsl:text>
			<span style="color: green">
				<xsl:value-of select="@href" />
			</span>
			<xsl:text>)</xsl:text>
		</span>
	</xsl:if>
</xsl:template>

Open in new window

0
Comment
Question by:numberkruncher
[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
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 22862603
seems to do what you want...
I don't think there is much to improve here

cheers

Geert
0
 
LVL 13

Author Comment

by:numberkruncher
ID: 22865891
Excellent, thanks for checking that for me. Some pages can have a lot of links, and I wanted to make sure that the XSLT was as efficient as possible so as not to kill my server when this thing goes live.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 22865934
welcome
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

764 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