html - How to compare XML element with XSL variable -


i using xslt transform xml document html use in email. need compare xml elements xml element value know format give value. have xml structure such:

<main>     <comparer>1</comparer>     <items>         <item>             <name>blarg</name>             <values>                 <value>1</value>                 <value>2</value>             </values>     </items> </main> 

the item information being used build table:

<table>     <tr>         <td>blarg</td>         <td>1</td>         <td>2</td>     </tr> </table> 

what need able use xsl compare item values 'comparer' node value , if equal bold cell in table otherwise cell value snot bolded. need accomplish without use of javascript has done in xsl. right now, looking @ using xsl:variable attempting use xsl:when compare. unfortunately, having little luck. have started playing each row in table:

<xsl:variable name="compare" select="//main/comparer" />  ...      <xsl:for-each select="value">     <td>         <xsl:choose>             <xsl:when test=". = $compare">                 <b>                     <xsl:value-of select="."/>                 </b>             </xsl:when>             <xsl:otherwise>                 <xsl:value-of select="."/>.             </xsl:otherwise>         </xsl:choose>     </td> </xsl:for-each> 

*note: left out of xsl brevity. i'm trying focus on issue.

i figured out after trial , error. alejandro's answer appears work, not have luxury of restructuring xsl make use of templating. here used solve issue:

<xsl:variable name="compare" select="//main/comparer" />  ...      <xsl:for-each select="value">     <td>         <xsl:choose>             <xsl:when test="contains(., $expiredate)">                 <b>                     <xsl:value-of select="."/>                 </b>             </xsl:when>             <xsl:otherwise>                 <xsl:value-of select="."/>.             </xsl:otherwise>         </xsl:choose>     </td> </xsl:for-each> 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -