Subject: RE: xsl:if
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 1 Apr 2005 17:52:55 +0100
|
A stylesheet has to be well-formed XML and this:
<xsl:if test="$id=<xsl:value-of select="id" />
isn't.
You're making things far too complicated, you just want
<xsl:if test="$id=id" />
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: tim [mailto:tim@xxxxxxxxxxx]
> Sent: 01 April 2005 17:14
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: xsl:if
>
> 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:if
- tim - 1 Apr 2005 16:19:38 -0000
- <Possible follow-ups>
- tim - 3 Apr 2005 18:42:30 -0000
|
|