xsl-list
[Top] [All Lists]

Re: [xsl] Problems with apersand (&) when trying to dynamically define a character value as an attribute value.

2006-10-26 04:54:46

Unfortunately I am restricted to using only xslt1. Is there any way to
define the character in XSLT1 using the code I have without having to
attach the & to the beginning? 

your processor may have an extension function (eg saxon:parse() would
work) or the answer to your question technically is yes but you really
don't want to do it

<xsl:choose>
<xsl:when test="@character=65">A</xsl:when>
<xsl:when test="@character=66">B</xsl:when>
.... a few thousand lines later....
</xsl:choose>

doing it as an xsl:choose would be painful, as it would have to do a
linear search each time. What would be not quite so painful is to make
yourself a document
<x>
<char num="65">A</char>
.... a few thousand lines later....
</x>

then you could have 
<xsl:key name="char" match="char" use="@num"/>
...

<xsl:variable name="c" select="@character"/>
<xsl:for-each select="document('char.xml')">
  <xsl:value-of select="key('char',$c)"/>
</xsl:for-each>

which would mean that having read the file once xslt had a hash table
lookup of character numbers, but still (if you want to cover all
unicode) this is still rather painful, and you may just prefer to get
xslt to write out [AMP]#1234; and then just use perl or sed or any other
text editor to change [AMP] to &

David


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--