RE: [xsl] Suppressing element content

Subject: RE: [xsl] Suppressing element content
From: "Scott Trenda" <Scott.Trenda@xxxxxxxx>
Date: Wed, 10 Sep 2008 16:50:32 -0500
You need to override the built-in templates. And your initial template
is the same as the built-in template, so you don't need it.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
	<xsl:output method="text" />
	<xsl:template match="Node[@Cat='x']">
		<xsl:value-of select="@Lemma" />
	</xsl:template>
	<xsl:template match="@*|text()" />
</xsl:stylesheet>

~ Scott

-----Original Message-----
From: Kirk Lowery [mailto:empirical.humanist@xxxxxxxxx]
Sent: Wednesday, September 10, 2008 4:32 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Suppressing element content

I'm using xsltproc on OS X 10.5 (Leopard), XSLT 1.0.

I have an input xml file of n-ary trees. Here's a simplified example
of the input:

     <Tree>
       <Node Cat="S" Head="0">
         <Node Id="3.1" Cat="CL" Start="0" End="1" Rule="V2CL"
Head="0" Type="Verbal">
           <Node Id="3.2" Cat="V" Start="0" End="1" Rule="Vp2V"
Head="0">
             <Node Id="3.3" Cat="vp" Start="0" End="1" Rule="V2VP"
Head="0">
               <Node Id="3.4" Cat="verb" Start="0" End="1"
Rule="VerbX" Head="0">
                 <Node Id="3.5" Cat="verb" Start="0" End="0"
Lemma="SWR">
                    S71W.R
                 </Node>
                 <Node Id="3.6" Cat="x" Start="1" End="1" Lemma="H"">
                   FH
                 </Node>
               </Node>
             </Node>
           </Node>
         </Node>
       </Node>
     </Tree>

What I want to do is to extract the contents of the Lemma attribute
whenever the Cat attribute is "x" into a simple text file. Here is the
stylesheet so far:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="Node[@Cat='x']">
    <xsl:value-of select="@Lemma"/>
  </xsl:template>
</xsl:stylesheet>

Expected output (from this simplified example input):

H

What I get is:

S71W.R
H

That is I get what I want, but I *also* get the contents of all Node
elements but, interestingly I don't get the element content of the
Node that is Cat="x".

What I've read and researched today says I'm doing what I want, but
obviously I'm missing something basic. Why am I getting all this extra
Node element content of the file in the output?

Thanks.

Kirk

Current Thread