This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Using xsl to test value of node
- From: "Chris Bayes" <chris at bayes dot co dot uk>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Thu, 13 Dec 2001 15:55:54 -0000
- Subject: RE: [xsl] Using xsl to test value of node
- Reply-to: xsl-list at lists dot mulberrytech dot com
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html"/>
<xsl:template match="LOG">
<xsl:apply-templates select="DIRECT"/>
</xsl:template>
<xsl:template match="DIRECT">
<xsl:apply-templates select="CHARACTER_ID"/> </xsl:template>
<xsl:template match = "CHARACTER_ID">
<xsl:if test="normalize-space()='44639'">
<xsl:apply-templates select="../LOCATION_ID"/>
</xsl:if>
</xsl:template>
<xsl:template match="LOCATION_ID">
<html>
<body>
<h1>
<xsl:value-of select="."/>
</h1>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Ciao Chris
XML/XSL Portal
http://www.bayes.co.uk/xml
> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of
> Ahmad J Reeves
> Sent: 13 December 2001 15:19
> To: XSL-List@lists.mulberrytech.com
> Cc: Ahmad Reeves
> Subject: [xsl] Using xsl to test value of node
>
>
> I am trying to test the value of a node
> and if it contains a certain value, then to extract
> a value from a second node, so here is an excerpt from the xml:
>
> <LOG>
> <DIRECT>
> <COMMUNICATION_TYPE> PAGETELL </COMMUNICATION_TYPE>
> <Invoc_serial> 27 </Invoc_serial>
> <Serial> 3087908 </Serial>
> <USAGE> TELL </USAGE>
> <MESSAGE_TYPE> EMOTE </MESSAGE_TYPE>
> <CHARACTER_ID> 44639 </CHARACTER_ID>
> <CHARACTER_STATUS> 3 </CHARACTER_STATUS>
> <LOCATION_ID> 45040 </LOCATION_ID>
> <TARGET_CHARACTER_ID> 23470 </TARGET_CHARACTER_ID>
> <TARGET_CHARACTER_STATUS> 6 </TARGET_CHARACTER_STATUS>
> <TARGET_CHARACTER_LOCATION_ID> 23222
> </TARGET_CHARACTER_LOCATION_ID>
> <MESSAGE> Hello </MESSAGE>
> <TIME> 'Mon, 26 Nov 2001 15:40:29 +0000' </TIME>
> </DIRECT>
> </LOG>
>
> So for example if <CHARACTER_ID> = 44639
> I need to output say in html format the value of <LOCATION_ID>
>
> Here is my first stab at the code (not working)
>
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xsl:output method="html"/>
>
> <xsl:template match="LOG">
> <xsl:apply-templates select="DIRECT"/>
> </xsl:template>
>
> <xsl:template match="DIRECT">
> <xsl:apply-templates select="CHARACTER_ID"/> </xsl:template>
>
> <xsl:template match = "CHARACTER_ID">
> <xsl:if test() ="44639"/>
> <xsl:apply-templates select="LOCATION_ID"/>
> </xsl:if>
> </xsl:template>
>
> <xsl:template name="LOCATION_ID">
> <html>
> <body>
> <h1>
> <xsl:value-of select="."/>
> </h1>
> </body>
> </html>
> </xsl:template>
> </xsl:stylesheet>
>
> I know xml-if only returns a true or false boolean value
> and have also tried setting variables but with no success.
>
> Thanks
>
> Ahmad
> -----------------------------------------------------
> Ahmad J. Reeves BSc(Hons), MSc(Dist). Phd Student
> Information, Media, and Communication Research Group,
> Dept of Computer Science,Queen Mary,University of London,
> E1 4NS Tel +44 (0)20 7882 5257
> http://www.dcs.qmw.ac.uk/imc/
> -----------------------------------------------------
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list