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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xsl href

Status
Not open for further replies.

shdavid

Programmer
Nov 3, 2007
1
IL
hello,

i'm trying to make a link from the xsl file to a file that appears in one of my xml tags.

my xml file:

<Alert>
<Service>All</Service>
<Link>ConnectionsRate_08_15_11#30-59_194.29.36.11_values.xml</Link>
</Alert>

my xsl file:

...
<td><xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="Link"/>
</xsl:attribute>
<xsl:value-of select="Service"/>
</xsl:element></td>
...

it works with one problem, the link is cut, the html result file contains a link to the first part of the file name. it's like there is a limitation on the link length.

does anyone knows how to solve this problem???

thanks!!
 
[1] The cases where the problem occurs is probably due the specific Link text is not properly url encoded.

[1.1]The simplest case for that to occur is that it contains a blank space. The effect would then be what described as if the link is truncated. In that case you have to replace it by a "+" (character for character).
><xsl:value-of select="Link"/>
[tt]<xsl:value-of select="translate(Link,' ','+')"/>[/tt]

[1.2] But that you can be considered lucky because ' ' is encoded to '+' both one character. translate() would be powerless to handle another valid escape "%20".

[1.3] Furthermore, translate() certainly cannot handler the full character-set that needs encoded which is in principle very big: that is the problem for xslt1.0 as there isn't built-in function for that. Also that's why to treat the general url encoding, it usually needs to resort to extension functions.

[2] If you use msxml technology, you can use xslt extension vbs/js with encodeURI() function to do the work. This can be done but it becomes platform dependent, but the flip side is that you get the problem taken care of. If not, you have to find an appropriate extension for the platform.

[2.1] There is another popular EXSLT library you can look into.
But the dependency on extension is still the same.

[2.2] In principle, one can devise a lookup table type to make the encoding by calling an external xml lookup table where the mapping is recorded (such as ' ' being mapped to '+' or '%20' etc...) But, it seems very unpractical as a general solution. If the problem is restricted to a very limited subset of characters to occur (and usually that might be the case), then a lookup table type approach is viable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top