Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL: link open in new window

Status
Not open for further replies.

opton

Technical User
Jun 18, 2005
9
US
Hoping somebody can help. I have links that appear using XML/XSL and i would like to have those links open in a new browser window. Here is the part of the XLS code to create the links:

<xsl:template match="piece">
<li>
<xsl:variable name="href">
<xsl:value-of select="link" />
</xsl:variable>
<xsl:variable name="name">
<xsl:value-of select="name" />
</xsl:variable>
<a href="{$href}">
<xsl:value-of select="name" />
</a>
</li>
</xsl:template>

Is there an easy what to have the links created open in a new window when clicked (similar to html <a href=" target="_blank">Site Name</a>)

I'm not very well versed in XSL or XML, so if more information is needed please just let me know.

Thank you.
 
Why don't you just use:
Code:
<xsl:template match="piece">
  <li>
    <a href="{link}" target="_blank">
      <xsl:value-of select="name" /> 
    </a>
  </li>
</xsl:template>

Jon

"Asteroids do not concern me, Admiral. I want that ship, not excuses.
 
FANTASTIC!!

Works exactly as i need it to! :)

Thank you so much for your help. I'm very to new to XML/XSL so i find it all very confusing, i'm grateful for users such as yourself who take the time to help out us newbies.
 
I have a follow up to this question. I have an xsl section that looks like this:
<xsl:template match="info">
<div style="font-size: small; margin-top: 10px">
<a>
<xsl:attribute name="href">
<xsl:value-of select="link"/>
</xsl:attribute>
Model Details
</a>
</div>

and I want my link to open either in a new window or even beter would be in the lower frame of my current window. I tried using <a href="{link}" target="_blank"> but that did not seem to work. any ideas?

-marc
 
Are you sure info/link is a node? What output does it give you?

Jon

"Asteroids do not concern me, Admiral. I want that ship, not excuses.
 
It would be easier to help you if you can provide a sample of the XML you are working with...

Like Jon suggested, check the info element and make sure it includes a sub node "link"
The names are case sensitive... "link" will not match <Link> but will match <link>

BTW... I have had trouble trouble getting <xsl:attribute> to work, but if it works for you...
you can try:
Code:
<xsl:template match="info">
 <div style="font-size: small; margin-top: 10px">
  <a>
<xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute>
[b]<xsl:attribute name="target">_blank</xsl:attribute>[/b]
Model Details
</a>
</div>
...


Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top