[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Looking Not Working for No Obvious Reason

Subject: RE: Looking Not Working for No Obvious Reason
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 20 Jun 2007 19:47:54 +0100
RE:  Looking Not Working for No Obvious Reason
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:  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
> www.innodata-isogen.com

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.