Subject: [xsl] problem: getting link text without document() function From: "Trevor Nicholls trevor@xxxxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 11 Sep 2018 10:55:00 -0000 |
Hello This list seems to have gone dormant but here goes I have a working XSLT 1 stylesheet which determines the text to insert in hyperlinks by identifying the linked elements in separate documents. I'm now incorporating it into an application which uses Xopus to edit a source XML document, and I have discovered that the stylesheet is only usable in IE. Unfortunately it barfs in Chrome and Firefox, because whatever XSL processor they use in those browsers does not support document(). The Xopus documentation implies that whatever I am trying to achieve in this stylesheet could be achieved using XIncludes (but they don't supply a useful example for my requirement). I have to concede that I was even less informed when I wrote this stylesheet than I am now, so it may be horribly over-engineered and misguided - but at least it has been working in IE (and in other contexts outside Xopus-in-a-browser). If anyone is able to direct me to a useful example, or provide some tips on how to achieve what I am doing without using document(), I would be very grateful. Part of the stylesheet fragment follows: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- local key for cross references --> <xsl:key name="link-id-key" match="*[@id]" use="@id" /> <!-- return the text that should be substituted in a link --> <xsl:template name="link_text"> <xsl:param name="linkurl" /> <xsl:variable name="lt-file"> <xsl:choose> <xsl:when test="contains($linkurl,'#')"> <xsl:value-of select="substring-before($linkurl,'#')" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$linkurl" /> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="lt-id" select="substring-after($linkurl,'#')" /> <!-- file or anchor-in-file --> <xsl:choose> <xsl:when test="$lt-id = ''"> <!-- FILE ONLY--> <xsl:variable name="candidate-text"> <xsl:for-each select="document($lt-file,/)"> <xsl:value-of select="normalize-space(./*/title)" /> </xsl:for-each> </xsl:variable> <xsl:choose> <!-- can find the file --> <xsl:when test="$candidate-text != ''"> <xsl:value-of select="$candidate-text" /> </xsl:when> <!-- can't find the file --> <xsl:otherwise> <xsl:text>UNFOUND EXTERNAL DOCUMENT: </xsl:text> <xsl:value-of select="$linkurl" /> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <!-- FILE#ID --> <xsl:variable name="simple-link"> <xsl:for-each select="document($lt-file,/)"> <xsl:value-of select="normalize-space(key('link-id-key',$lt-id))" /> </xsl:for-each> </xsl:variable> <xsl:choose> <!-- can find the file --> <xsl:when test="$simple-link != ''"> <xsl:value-of select="$simple-link" /> </xsl:when> <!-- can't find the file --> <xsl:otherwise> <xsl:text>UNFOUND EXTERNAL REFERENCE: </xsl:text> <xsl:value-of select="$linkurl" /> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </xsl:template> By the way, can anyone tell me what has happened to Dave Pawson's invaluable XSLT FAQ? I remember using it almost daily for a while and I feel a great loss now that its seems to have vanished from the web Thanks T
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] make money really!, Dstar productions fr | Thread | Re: [xsl] problem: getting link tex, Michael Kay mike@xxx |
[xsl] make money really!, Dstar productions fr | Date | Re: [xsl] problem: getting link tex, Michael Kay mike@xxx |
Month |