Within my style sheet I need to be able to map between pairs of strings
(in this case, long and short titles).
I've tried to implement this by using an internal document-node()
variable that defines the mapping and then using a function to do
lookups against the map.
The map looks like this (declared as a stylesheet-scope variable):
<xsl:variable name="sectionTitleMap" as="document-node()">
<xsl:document>
<map>
<item>
<shorttitle>Background</shorttitle>
<longtitle>Overview and Background</longtitle>
</item>
<item>
<shorttitle>Scope</shorttitle>
<longtitle>Scope and Scope Exceptions</longtitle>
</item>
<item>
<shorttitle>Glossary</shorttitle>
<longtitle>Topical Definitions - Glossary</longtitle>
</item>
</map>
</xsl:document>
<xsl:variable>
I then have this function to do lookups:
<xsl:function
name="func:getShortTitleForSection" as="xs:string">
<xsl:param
as="xs:string"
name="sectionBaseTitle"/>
<xsl:choose>
<xsl:when test="count($sectionTitleMap//longtitle[. =
$sectionBaseTitle]) = 1">
<xsl:sequence select="$sectionTitleMap//item[longtitle[. =
$sectionBaseTitle]]/shorttitle"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="$sectionBaseTitle"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
As far as I can see this should just work, assuming my input parameter
occurs in the table.
However, what I'm getting is that this works as expected for *some*
input strings but not for others, where I've verified that the input
strings match the values in the map.
I must be doing something wrong but I can't figure out what it might
be--the fact that some input values work and others don't is odd.
Anyone have any idea what might be going wrong or what I can do to track
down the bug? I've done things like copied a mapping target from my
input document into the map just to be 100% sure the string is the same,
but I still get the failure, so it doesn't appear to be something subtle
like invisible characters in the input or some such (which I wouldn't
expect in this case, but you never know).
The real mapping is small enough I could rewrite the code to use
choose/when for the mappings but this seemed like the most efficient way
to do a two-way mapping in XSLT.
Thanks,
Eliot
--
W. Eliot Kimber
Professional Services
Innodata Isogen
8500 N. Mopac, Suite 402
Austin, TX 78759
(214) 954-5198
ekimber@xxxxxxxxxxxxxxxxxxx
www.innodata-isogen.com