Re: Display HyperLink
Hi Kevin, Last things first: > I am trying to display the XML on an HTML page using an XSL > stylesheet. If you look through the archives you'll probably find I've given similar advice before: don't use processes that do something after the transformation. What essentially is happening now is: the browser sees the stylesheet -> input goes through xml parser -> xml is produced -> stylesheet and input xml called and goes through xslt processor -> HTML is produced -> browser processes HTML. A lot of things can happen in this last step that confuses people. Try instead getting the sample xml and running it though at the command-line via an XML processor like Saxon. >If I do a regular value-of, then I get the formatted link > below, but I want it to display as an actual clickable hyperlink. > Sorry for the confusion, the actual field in the XML doc is: > c6='<a href=..\ASP\InvoiceReprint\BARInv_Reprint_View_Frame.asp?Inv_Num=358778> 358778</a>' Rereading the email I realized I thought you meant that you were getting that xml from another process and trying to convert it to html. I assume by "field" you mean attribute. Embedding like this is just ugly, ugly, ugly practice for producing xml, but I realize there's a good chance you can't change it. If you can change the XML I recommend doing it right away. The problem is that to XSLT the stuff between the ' ' is considered nothing more than an attribute value, plain text as far as we are concerned here. As for how it's displaying there could be two issues here. One is the xml parser is replacing the unicode character entities with their counterparts, so < becomes <. This is essentially the same as putting in <. Otherwise it might pass through depending on the parser to where your browser font is doing the appropriate thing displaying those characters as <. There is nothing there besides an attribute value for XSLT to work with. So you're going to need to some string processing (see the string functions in xpath 1.0/xslt 1.0. I'm afraid if you're targetting this as browser as the end point you're stuck with XSLT 1.0. Do you want XHTML or HTML as output? If XHTML you're still going to have a problem with the missing quotation marks for the href. We could perhaps use some extentions to convert it to a node, but then we still have problems with the attribute not being valid xml. (If anyone else is still reading this email and knows a node-set extension that just would take it anyhow, feel free to chime in). I'll try to take a stab at a possible solution, but this is a bit more complicated of a problem than I have time to test now. Hopefully with all the unicode references gmail doesn't mangle this. See the text of the original email if it does. <xsl:variable name="embedlink" select="@c6"/> <xsl:variable name="url" select='substring-before(substring-after($embedlink),"="),">")'/> <xsl:variable name="anchtext" select='substring-before(substring-after($embedlink),">"),"<")'/> <xsl:element name="a"> <xsl:attribute name="href"><xsl:value-of select="$url"/></xsl:attribute> <xsl:value-of select="$anchtext"/> </xsl:element> Essentially, the above takes the substring from the = sign to the end of the string producing: ..\ASP\InvoiceReprint\BARInv_Reprint_View_Frame.asp?Inv_Num=358778>35877 8</a>, then extracts the substring from takes another substring from the > ..\ASP\InvoiceReprint\BARInv_Reprint_View_Frame.asp?Inv_Num=358778 The other variable works in a similar way, taking everything after the first > and everything from before the first < after the first >. I'm sure there's a far spiffer way in xslt 2.0 but you're stuck with a browser approach you're stuck with XSLT 1.0. Sorry if the email is longish but I'm hoping to cut off any confusion. We'll see if it backfires ;).
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format