Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Construct a href= using XSLT

Tags:

xslt

I want to create this:

<a href="domain.com?=USERNAME">Login</a>

where USERNAME = in XML so the HTML output is specific to the user currently logged in. Can anyone advise?

I know I can use:

<xsl:variable name="class" select="a:Subject"/>
<p class="{$class}">English</p>

To extract a value and use it as a CSS Class but what about using it for a link?

like image 203
CLiown Avatar asked Sep 21 '09 12:09

CLiown


People also ask

How do I hyperlink in XSLT?

XSLT doesn't do hyperlinks. Rethink your question. When thinking about how to achieve something like this in XSLT, split the task into two: (a) decide what HTML you want to generate, and (b) decide what XSLT code you need in order to generate it.

What is XSLT in HTML?

XSLT (Extensible Stylesheet Language Transformations) is a language originally designed for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subsequently be converted to other formats, such as PDF, PostScript and PNG.

Can you use CSS with XSLT?

Incorporating <STYLE> Elements into an XSLT FileAn XSLT style sheet can emit HTML <STYLE> elements, including CSS specifications, directly into the HTML that results from the XSLT transformation. This option works best when the number of CSS rules is small and easily managed.

What is text () in XSLT?

The <xsl:text> element is used to write literal text to the output. Tip: This element may contain literal text, entity references, and #PCDATA.


3 Answers

Think I might have answered it myself:

<xsl:variable name="username" select="Username"/>
<a href="{$username}">Login</a>
like image 131
CLiown Avatar answered Sep 17 '22 06:09

CLiown


What's wrong with using xsl:attribute?

<a><xsl:attribute name='href' select='Username' />Login</a>
like image 20
Wim ten Brink Avatar answered Sep 21 '22 06:09

Wim ten Brink


The same

<a href="domain.com?={$user}">OMG!</a>
like image 36
Michael Krelin - hacker Avatar answered Sep 20 '22 06:09

Michael Krelin - hacker