Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to put a XSLT filter condition?

Status
Not open for further replies.

SilverStray

Programmer
Oct 25, 2001
47
AU
Hi,

I'm want to have the following output:

Document A : FA
Description: Funny Animals

Document C : FRF
Description: Fruitful Fantasy

-->And this is my XML data:

<documentData>
<document>
<type>A</type>
<name>FA</name>
<desc>Funny Animals</desc>
</document>

<document>
<type>B</type>
<name>TRVL</name>
<desc>Travel</desc>
</document>

<document>
<type>C</type>
<name>FRF</name>
<desc>Fruitful Fantasy</desc>
</document>

<document>
...(other document codes in here)
</document
</documentData>

I tried to use <xsl:apply-templates select="document" but it seems wrong as I need to get document type A and C only.
How can I filter them out from the document node?

Thanks in advance!

J. Echavez
 
This should work:

Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
	<xsl:template match="/">
		<xsl:apply-templates select="documentData/document[./type/text() = 'A' or ./type/text() = 'C']"></xsl:apply-templates>
	</xsl:template>
	<xsl:template match="document">
name:
		<xsl:value-of select="name"/>
		<br></br>
desc:
		<xsl:value-of select="desc"/>
		<br></br>
	</xsl:template>
</xsl:stylesheet>

.. by adding axis to your xsl:applytemplates call we have effectively restricted the information passed to the xsl:template matching "document".

If you can't work out how this works, just let me know.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top