Altova Mailing List Archives

RE: [xsl] Looking Not Working for No Obvious Reason

From: "Michael Kay" <mike@------------>
Date: 6/20/2007 6:48:00 PM
Can't see anything wrong with the code, I think you need to supply a
reproducible case where it doesn't work.

Your xsl:choose could be replaced by the rather more concise:

<xsl:sequence select="($sectionTitleMap/map/item[longtitle =
$sectionBaseTitle]/shorttitle, $sectionBaseTitle)[1]"/>

and if the lookup list is lengthy you could improve performance using keys
(though Saxon-SA will do this for you automatically).

Michael Kay

> -----Original Message-----
> From: Eliot Kimber [mailto:ekimber@xxxxxxxxxxxxxxxxxxx] 
> Sent: 20 June 2007 19:15
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Looking Not Working for No Obvious Reason
> 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


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.