How Can I Reduce "When" Statement in XSLT
Hello I am writing a XSLT statement where I need to implement 1500 conditional statements like -
<xsl:when test="ID = '51'">
<br>
<xsl:text>background: url('rightcolumn_seniorliv.jpg') no-repeat;</xsl:text>
<br>
</xsl:when>
<br>
<xsl:when test="ID = '52'">
<br>
<xsl:text开发者_JS百科>background: url('rightcolumn_seniorliv.jpg') no-repeat;</xsl:text>
<br>
</xsl:when>
If i write statement like this way then my pages will be very slow. How can i reduce my code and write this statement in a smart way?
<xsl:variable name="idlist">
<ids>
<id>50</id>
<id>59</id>
<id>66</id>
...
</ids>
</xsl:variable>
<xsl:key name="idk" match="id" use="."/>
<xsl:when test="key('idk', ID, $idlist)">...
This is XSLT 2.0 but can be adapted to work with 1.0.
I can't see all your cases, but if the pattern from your first two continues and you want that same 'rightcolumn_seniorliv.jpg' for IDs 51 thru 1551 then
<xsl: when test="ID>'50' and ID<'1552'">
it sounds like these ID cases are going well beyond logic and into the data realm. i obviously dont know anything about your app, but perhaps an ID to imagename mapping somewhere (probably database) would be in order. depending on what process generates the XML file (the first one, before XSLT transformation), you might want to just set the image name (or lack thereof) explicitly thru this mapping. then lose the when
all together
精彩评论