[xsl] Looking Not Working for No Obvious Reason

Subject: [xsl] Looking Not Working for No Obvious Reason
From: "Eliot Kimber" <ekimber@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 20 Jun 2007 13:15:27 -0500
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()">
        <longtitle>Overview and Background</longtitle>
        <longtitle>Scope and Scope Exceptions</longtitle>
        <longtitle>Topical Definitions - Glossary</longtitle>

I then have this function to do lookups:

name="func:getShortTitleForSection" as="xs:string">
<xsl:when test="count($sectionTitleMap//longtitle[. = $sectionBaseTitle]) = 1">
<xsl:sequence select="$sectionTitleMap//item[longtitle[. = $sectionBaseTitle]]/shorttitle"/>
<xsl:sequence select="$sectionBaseTitle"/>


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.



W. Eliot Kimber
Professional Services
Innodata Isogen
8500 N. Mopac, Suite 402
Austin, TX 78759
(214) 954-5198


Current Thread