Suppressing the display of elements

J

Jim

Hi

I have foo.xml:

<file>
<area1>
<name>John</name>
<age>22</age>
</area1>

<area2>
<weight>200</weight>
<height>73in</height>
</area2>
</file>

I have foo.xsl:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:eek:utput method="text"/>

<xsl:template match="file/area1">
<xsl:value-of select="name"/>
<xsl:value-of select="age"/>
</xsl:template>

<xsl:template match="file/area2">
<xsl:value-of select="height"/>
<xsl:value-of select="weight"/>
</xsl:template>

</xsl:stylesheet>


I only want area1 and area2 information displayed. However, when I
apply this stylesheet, I get everything. How do I ignore/suppress area2
in foo.xml?
 
B

b0yce

That's because it is using the built in templates since you haven't
explicitly called <xsl:apply-templates ../> for each area!

Add this below your <xsl:eek:utput ... /> and it should work.

<xsl:templates match="/">
<xsl:apply-templates select="file/area1" />
<xsl:apply-templates select="file/area2" />
</xsl:template>

b0yce
 
M

Martin Honnen

Jim wrote:

I have foo.xml:

<file>
<area1>
<name>John</name>
<age>22</age>
</area1>

<area2>
<weight>200</weight>
<height>73in</height>
</area2>
</file>

I have foo.xsl:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:eek:utput method="text"/>

<xsl:template match="file/area1">
<xsl:value-of select="name"/>
<xsl:value-of select="age"/>
</xsl:template>

<xsl:template match="file/area2">
<xsl:value-of select="height"/>
<xsl:value-of select="weight"/>
</xsl:template>

</xsl:stylesheet>


I only want area1 and area2 information displayed. However, when I
apply this stylesheet, I get everything. How do I ignore/suppress area2
in foo.xml?

If you use an empty template
<xsl:template match="area2" />
matching area2 you will not get any output.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top