Re: [xsl] xsl:if

Subject: Re: [xsl] xsl:if
From: António Mota <amsmota@xxxxxxxxx>
Date: Fri, 1 Apr 2005 17:29:56 +0100
This

<xsl:if test="$id=<xsl:value-of select="id" />

should be only

<xsl:if test="$id=id" />

and perhaps you should do

<xsl:template match="npcs">
<table width="75%" border="1">

    <xsl:apply-templates select="*"/>

</table>

</xsl:template>

but i didn't test it.

On Apr 1, 2005 5:13 PM, tim <tim@xxxxxxxxxxx> wrote:
> Hello. I am new to XSL and am having a problem with using xsl:if.
> I have passed a parameter (id) from some javascript into the XSL
> stylesheet. I know this works  because I can output the value of ID in
> the html produced.
> However what I want is to only output html if the ID value in the XML
> matches the value of ID passed.
> I have tried the xsl:if in a variety of places and had no luck. Looking
> through FAQ and deja I have not found anyone doing this so I am starting
> to think I have got the wrong end of the stick fairly badly.
> Any help would be much appreciated, even if it is to tell me where to
> look to learn how to do this. I realise that ID should possibly be the
> parent to the other elements, but started to get the feeling that was
> not necessarily true.
> Sorry in advance if this is too stupid a question.
> I am using the XSLTProcessor in Firefox 1.02
> 
> The XML looks like this
> ------------------------------------------------------
> <npcs>
> <char>
> <id>28</id>
> <name>Bonrist</name>
> <location>Vanard</location>
> <charinfo>Shemtaa</charinfo>
> <prof/>
> <realprof>Thief</realprof>
> <localknown>0</localknown>
> <countryknown/>
> <gminfo>hello</gminfo>
> </char>
> -
>     <char>
> <id>29</id>
> <name>Dynl</name>
> <location>Vanard</location>
> <charinfo>Elf</charinfo>
> <prof/>
> <realprof>Thief</realprof>
> <localknown>0</localknown>
> <countryknown/>
> <gminfo>hello</gminfo>
> </char>
> </npcs>
> ---------------------------------------------------
> The XSL I am using looks like this
> <xsl:stylesheet version="1.0"
>     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> <!-- root node-->
> <xsl:output method="html"/>
> <xsl:param name="id"/>
> <xsl:template match="/">
> <html>
> <body>
> <h2>Character info</h2>
> <xsl:apply-templates />
> </body>
> </html>
> </xsl:template>
> 
> <!-- into the npc node -->
> <xsl:template match="npcs">
>  <table width="75%" border="1">
> 
>       <xsl:apply-templates>
>        </xsl:apply-templates>
> 
> </table>
> 
> </xsl:template>
> 
> <!-- into namenodes -->
> 
> <xsl:template match="char">
> <xsl:if test="$id=<xsl:value-of select="id" />
>   <tr>
>     <td>Name :</td>
>     <td colspan="3"><xsl:value-of select="name" /></td>
>   </tr>
>   <tr>
>     <td>Known Profession :</td>
>     <td><xsl:value-of select="prof" /></td>
>     <td>Real Profession :</td>
>     <td><xsl:value-of select="realprof" /></td>
>   </tr>
>   <tr>
>     <td>Public Information :</td>
>     <td colspan="3"><xsl:value-of select="charinfo" /></td>
>   </tr>
>   <tr>
>     <td>Private Information :</td>
>     <td colspan="3"><xsl:value-of select="$id" /></td>
>   </tr>
>   <tr>
>     <td>Address Info :</td>
>     <td  rowspan="2"></td>
>     <td>Local Fame Rating :</td>
>     <td><xsl:value-of select="localknown" /></td>
>   </tr>
>   <tr>
>     <td></td>
>     <td>Country Fame Rating :</td>
>     <td><xsl:value-of select="countryknown" /></td>
>   </tr>
>  </xsl:if>
> </xsl:template>
> 
> </xsl:stylesheet>

Current Thread
  • [xsl] xsl:if
    • tim - Fri, 01 Apr 2005 18:13:57 +0200
      • António Mota - Fri, 1 Apr 2005 17:29:56 +0100 <=
      • David Carlisle - Fri, 1 Apr 2005 17:34:11 +0100
      • Michael Kay - Fri, 1 Apr 2005 17:52:55 +0100
      • <Possible follow-ups>
      • tim - Sun, 03 Apr 2005 20:41:55 +0200